<!DOCTYPE html><html class=split lang=en-US-x-hixie><script src=../link-fixup.js defer=""></script>
<!-- Mirrored from html.spec.whatwg.org/multipage/browsing-the-web.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 10 Sep 2025 08:35:53 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<meta charset=utf-8><meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name=viewport><title>HTML Standard</title><meta content=#3c790a name=theme-color><meta content="light dark" name=color-scheme><link rel=stylesheet href=../../resources.whatwg.org/standard-shared-with-dev.css crossorigin=""><link rel=stylesheet href=../../resources.whatwg.org/standard.css crossorigin=""><link rel=stylesheet href=../../resources.whatwg.org/spec.css crossorigin=""><link rel=icon href=https://resources.whatwg.org/logo.svg crossorigin=""><link rel=stylesheet href=../styles.css crossorigin=""><script>
   function toggleStatus(div) {
     div.parentNode.classList.toggle('wrapped');
   }
   function setLinkFragment(link) {
     link.hash = location.hash;
   }
  </script><body>
  
  <script defer="" crossorigin="" src=../html-dfn.js></script>
  
  <header id=head class="head with-buttons">
   <a href=https://whatwg.org/ class=logo><img width=100 alt=WHATWG crossorigin="" class=darkmode-aware src=https://resources.whatwg.org/logo.svg height=100></a>
   <hgroup><h1 class=allcaps>HTML</h1><p id=living-standard>Living Standard — Last Updated <span class=pubdate>10 September 2025</span></hgroup>
   
   

   
  </header>

  

  

  

  
  

  
  

  

  <nav><a href=document-sequences.html>← 7.3 Infrastructure for sequences of documents</a> — <a href=index.html>Table of Contents</a> — <a href=document-lifecycle.html>7.5 Document lifecycle →</a></nav><ol class=toc><li id=toc-browsers><ol><li><a href=browsing-the-web.html#navigation-and-session-history><span class=secno>7.4</span> Navigation and session
  history</a><ol><li><a href=browsing-the-web.html#session-history-infrastructure><span class=secno>7.4.1</span> Session history</a><ol><li><a href=browsing-the-web.html#session-history-entries><span class=secno>7.4.1.1</span> Session history entries</a><li><a href=browsing-the-web.html#document-state><span class=secno>7.4.1.2</span> Document state</a><li><a href=browsing-the-web.html#centralized-modifications-of-session-history><span class=secno>7.4.1.3</span> Centralized modifications of session history</a><li><a href=browsing-the-web.html#low-level-operations-on-session-history><span class=secno>7.4.1.4</span> Low-level operations on session history</a></ol><li><a href=browsing-the-web.html#navigating-across-documents><span class=secno>7.4.2</span> Navigation</a><ol><li><a href=browsing-the-web.html#navigation-supporting-concepts><span class=secno>7.4.2.1</span> Supporting concepts</a><li><a href=browsing-the-web.html#beginning-navigation><span class=secno>7.4.2.2</span> Beginning navigation</a><li><a href=browsing-the-web.html#ending-navigation><span class=secno>7.4.2.3</span> Ending navigation</a><ol><li><a href=browsing-the-web.html#the-usual-cross-document-navigation-case><span class=secno>7.4.2.3.1</span> The usual cross-document navigation case</a><li><a href=browsing-the-web.html#the-javascript:-url-special-case><span class=secno>7.4.2.3.2</span> The <code>javascript:</code> URL special case</a><li><a href=browsing-the-web.html#scroll-to-fragid><span class=secno>7.4.2.3.3</span> Fragment navigations</a><li><a href=browsing-the-web.html#non-fetch-schemes-and-external-software><span class=secno>7.4.2.3.4</span> Non-fetch schemes and external software</a></ol><li><a href=browsing-the-web.html#preventing-navigation><span class=secno>7.4.2.4</span> Preventing navigation</a><li><a href=browsing-the-web.html#aborting-navigation><span class=secno>7.4.2.5</span> Aborting navigation</a></ol><li><a href=browsing-the-web.html#reloading-and-traversing><span class=secno>7.4.3</span> Reloading and traversing</a><li><a href=browsing-the-web.html#navigate-non-frag-sync><span class=secno>7.4.4</span> Non-fragment synchronous "navigations"</a><li><a href=browsing-the-web.html#populating-a-session-history-entry><span class=secno>7.4.5</span> Populating a session history entry</a><li><a href=browsing-the-web.html#applying-the-history-step><span class=secno>7.4.6</span> Applying the history step</a><ol><li><a href=browsing-the-web.html#updating-the-traversable><span class=secno>7.4.6.1</span> Updating the traversable</a><li><a href=browsing-the-web.html#updating-the-document><span class=secno>7.4.6.2</span> Updating the document</a><li><a href=browsing-the-web.html#revealing-the-document><span class=secno>7.4.6.3</span> Revealing the document</a><li><a href=browsing-the-web.html#scrolling-to-a-fragment><span class=secno>7.4.6.4</span> Scrolling to a fragment</a><li><a href=browsing-the-web.html#persisted-user-state-restoration><span class=secno>7.4.6.5</span> Persisted history entry state</a></ol></ol></ol></ol><h3 id=navigation-and-session-history><span class=secno>7.4</span> <span id=history></span>Navigation and session
  history<a href=#navigation-and-session-history class=self-link></a></h3>

  <p>Welcome to the dragon's maw. Navigation, session history, and the traversal through that
  session history are some of the most complex parts of this standard.</p>

  <p>The basic concept may not seem so difficult:</p>

  <ul><li><p>The user is looking at a <a id=navigation-and-session-history:navigable href=document-sequences.html#navigable>navigable</a> that is presenting its <a href=document-sequences.html#nav-document id=navigation-and-session-history:nav-document>active document</a>. They <a href=#navigate id=navigation-and-session-history:navigate>navigate</a> it to another
   <a id=navigation-and-session-history:url href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a>.<li><p>The browser fetches the given URL from the network, using it to <a href="#attempt-to-populate-the-history-entry's-document" id="navigation-and-session-history:attempt-to-populate-the-history-entry's-document">populate</a> a new <a href=#session-history-entry id=navigation-and-session-history:session-history-entry>session history entry</a>
   with a newly-<a href=document-lifecycle.html#initialise-the-document-object id=navigation-and-session-history:initialise-the-document-object>created</a>
   <code id=navigation-and-session-history:document><a href=dom.html#document>Document</a></code>.<li><p>The browser updates the <a id=navigation-and-session-history:navigable-2 href=document-sequences.html#navigable>navigable</a>'s <a href=document-sequences.html#nav-active-history-entry id=navigation-and-session-history:nav-active-history-entry>active session history entry</a> to the newly-populated
   one, and thus updates the <a href=document-sequences.html#nav-document id=navigation-and-session-history:nav-document-2>active document</a> that it is showing
   to the user.<li><p>At some point later, the user <a href=#traverse-the-history-by-a-delta id=navigation-and-session-history:traverse-the-history-by-a-delta>presses the
   browser back button</a> to go back to the previous <a href=#session-history-entry id=navigation-and-session-history:session-history-entry-2>session history
   entry</a>.<li><p>The browser looks at the <a href=#she-url id=navigation-and-session-history:she-url>URL</a> stored in that <a href=#session-history-entry id=navigation-and-session-history:session-history-entry-3>session
   history entry</a>, and uses it to re-fetch and <a href="#attempt-to-populate-the-history-entry's-document" id="navigation-and-session-history:attempt-to-populate-the-history-entry's-document-2">populate</a> that entry's <a href=#she-document id=navigation-and-session-history:she-document>document</a>.<li><p>The browser again updates the <a id=navigation-and-session-history:navigable-3 href=document-sequences.html#navigable>navigable</a>'s <a href=document-sequences.html#nav-active-history-entry id=navigation-and-session-history:nav-active-history-entry-2>active session history entry</a>.</ul>

  <p>You can see some of the intertwined complexity peeking through here, in how traversal can
  cause a navigation (i.e., a network fetch to a stored URL), and how a navigation necessarily
  needs to interface with the session history list to ensure that when it finishes the user is
  looking at the right thing. But the real problems come in with the various edge cases and
  interacting web platform features:</p>

  <ul><li><p><a href=document-sequences.html#child-navigable id=navigation-and-session-history:child-navigable>Child navigables</a> (e.g., those contained in
   <code id=navigation-and-session-history:the-iframe-element><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code>s) can also navigate and traverse, but those navigations need to be
   linearized into <a href=document-sequences.html#tn-session-history-entries id=navigation-and-session-history:tn-session-history-entries>a single session history list</a>
   since the user only has a single back/forward interface for the entire <a id=navigation-and-session-history:traversable-navigable href=document-sequences.html#traversable-navigable>traversable
   navigable</a> (e.g., browser tab).<li><p>Since the user can traverse back more than a single step in the session history (e.g., by
   holding down their back button), they can end up traversing multiple <a href=document-sequences.html#navigable id=navigation-and-session-history:navigable-4>navigables</a> at the same time when <a href=document-sequences.html#child-navigable id=navigation-and-session-history:child-navigable-2>child navigables</a> are involved. This needs to be synchronized across all of
   the involved navigables, which might involve multiple <a href=webappapis.html#event-loop id=navigation-and-session-history:event-loop>event
   loops</a> or even <a href=https://tc39.es/ecma262/#sec-agent-clusters id=navigation-and-session-history:agent-cluster data-x-internal=agent-cluster>agent clusters</a>.<li><p>During navigation, servers can respond with 204 or 205 status codes or with `<code id=navigation-and-session-history:http-content-disposition><a data-x-internal=http-content-disposition href=https://httpwg.org/specs/rfc6266.html>Content-Disposition: attachment</a></code>` headers, which cause
   navigation to abort and the <a id=navigation-and-session-history:navigable-5 href=document-sequences.html#navigable>navigable</a> to stay on its original <a href=document-sequences.html#active-document id=navigation-and-session-history:active-document>active document</a>. (This is much worse if it happens during a traversal-initiated
   navigation!)<li><p>Various other HTTP headers, such as `<code>Location</code>`,
   `<code id=navigation-and-session-history:refresh><a href=speculative-loading.html#refresh>Refresh</a></code>`, `<code id=navigation-and-session-history:x-frame-options><a href=speculative-loading.html#x-frame-options>X-Frame-Options</a></code>`, and those for Content Security Policy,
   contribute to either the <a href=#create-navigation-params-by-fetching id=navigation-and-session-history:create-navigation-params-by-fetching>fetching
   process</a>, or the <a href=document-lifecycle.html#initialise-the-document-object id=navigation-and-session-history:initialise-the-document-object-2><code>Document</code>-creation
   process</a>, or both. The `<code id=navigation-and-session-history:cross-origin-opener-policy-2><a href=browsers.html#cross-origin-opener-policy-2>Cross-Origin-Opener-Policy</a></code>` header even contributes
   to the <a href=browsers.html#browsing-context-group-switches-due-to-cross-origin-opener-policy>browsing
   context selection and creation</a> process!<li><p>Some navigations (namely <a href=#scroll-to-fragid>fragment navigations</a> and <a href=#navigate-non-frag-sync>single-page app navigations</a>) are synchronous, meaning that
   JavaScript code expects to observe the navigation's results instantly. This then needs to be
   synchronized with the view of the session history that all other <a href=document-sequences.html#navigable id=navigation-and-session-history:navigable-6>navigables</a> in the tree see, which can be subject to race conditions
   and necessitate resolving conflicting views of the session history.<li><p>The platform has accumulated various exciting navigation-related features that need
   special-casing, such as <code id=navigation-and-session-history:the-javascript:-url-special-case><a href=#the-javascript:-url-special-case>javascript:</a></code> URLs, <code id=navigation-and-session-history:attr-iframe-srcdoc><a href=iframe-embed-object.html#attr-iframe-srcdoc>srcdoc</a></code> <code id=navigation-and-session-history:the-iframe-element-2><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code>s, and the <code id=navigation-and-session-history:event-beforeunload><a href=indices.html#event-beforeunload>beforeunload</a></code> event.</ul>

  <p>In what follows, we have attempted to guide the reader through these complexities by
  appropriately cordoning them off into labeled sections and algorithms, and giving appropriate
  words of introduction where possible. Nevertheless, if you wish to truly understand navigation
  and session history, <a href=introduction.html#how-to-read-this-specification>the usual advice</a> will be
  invaluable.</p>


  <h4 id=session-history-infrastructure><span class=secno>7.4.1</span> <span id=the-session-history-of-browsing-contexts></span>Session history<a href=#session-history-infrastructure class=self-link></a></h4>

  <h5 id=session-history-entries><span class=secno>7.4.1.1</span> Session history entries<a href=#session-history-entries class=self-link></a></h5>

  <p>A <dfn id=session-history-entry>session history entry</dfn> is a <a id=session-history-entries:struct href=https://infra.spec.whatwg.org/#struct data-x-internal=struct>struct</a> with the following <a href=https://infra.spec.whatwg.org/#struct-item id=session-history-entries:struct-item data-x-internal=struct-item>items</a>:</p>

  <ul><li><p><dfn id=she-step>step</dfn>, a non-negative integer or "<code>pending</code>", initially "<code>pending</code>".<li><p><dfn id=she-url>URL</dfn>, a <a id=session-history-entries:url href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a><li><p><dfn id=she-document-state>document state</dfn>, a <a href=#document-state-2 id=session-history-entries:document-state-2>document
   state</a>.<li><p id=she-serialized-state><dfn id=she-classic-history-api-state>classic history API
   state</dfn>, which is <a href=#serialized-state id=session-history-entries:serialized-state>serialized state</a>, initially
   <a id=session-history-entries:structuredserializeforstorage href=structured-data.html#structuredserializeforstorage>StructuredSerializeForStorage</a>(null).<li><p><dfn id=she-navigation-api-state>navigation API state</dfn>, which is a
   <a href=#serialized-state id=session-history-entries:serialized-state-2>serialized state</a>, initially
   <a id=session-history-entries:structuredserializeforstorage-2 href=structured-data.html#structuredserializeforstorage>StructuredSerializeForStorage</a>(undefined).<li><p><dfn id=she-navigation-api-key>navigation API key</dfn>, which is a string,
   initially set to the result of <a id=session-history-entries:generating-a-random-uuid href=https://w3c.github.io/webcrypto/#dfn-generate-a-random-uuid data-x-internal=generating-a-random-uuid>generating a random UUID</a>.<li><p><dfn id=she-navigation-api-id>navigation API ID</dfn>, which is a string, initially
   set to the result of <a id=session-history-entries:generating-a-random-uuid-2 href=https://w3c.github.io/webcrypto/#dfn-generate-a-random-uuid data-x-internal=generating-a-random-uuid>generating a random UUID</a>.<li><p><dfn id=she-scroll-restoration-mode>scroll restoration mode</dfn>, a <a href=#scroll-restoration-mode id=session-history-entries:scroll-restoration-mode>scroll
   restoration mode</a>, initially "<code id=session-history-entries:dom-scrollrestoration-auto><a href=#dom-scrollrestoration-auto>auto</a></code>".<li><p><dfn id=she-scroll-position>scroll position data</dfn>, which is scroll position
   data for the <a href=#she-document id=session-history-entries:she-document>document</a>'s <a href=#restorable-scrollable-regions id=session-history-entries:restorable-scrollable-regions>restorable scrollable
   regions</a>.<li>
    <p id=an-entry-with-persisted-user-state><dfn id=she-other>persisted user state</dfn>,
    which is <a id=session-history-entries:implementation-defined href=https://infra.spec.whatwg.org/#implementation-defined data-x-internal=implementation-defined>implementation-defined</a>, initially null</p>

    <p class=example>For example, some user agents might want to persist the values of form
    controls.</p>

    <p class=note>User agents that persist the value of form controls are encouraged to also
    persist their directionality (the value of the element's <code id=session-history-entries:attr-dir><a href=dom.html#attr-dir>dir</a></code>
    attribute). This prevents values from being displayed incorrectly after a history traversal
    when the user had originally entered the values with an explicit, non-default
    directionality.</p>
   </ul>

  <p>To get a <a href=#session-history-entry id=session-history-entries:session-history-entry>session history entry</a>'s <dfn id=she-document>document</dfn>,
  return its <a href=#she-document-state id=session-history-entries:she-document-state>document state</a>'s <a href=#document-state-document id=session-history-entries:document-state-document>document</a>.</p>

  <hr>

  <p id=state-object><dfn id=serialized-state>Serialized state</dfn> is a serialization (via
  <a id=session-history-entries:structuredserializeforstorage-3 href=structured-data.html#structuredserializeforstorage>StructuredSerializeForStorage</a>) of an object representing a user interface state. We
  sometimes informally refer to "state objects", which are the objects representing user interface
  state supplied by the author, or alternately the objects created by deserializing (via
  <a id=session-history-entries:structureddeserialize href=structured-data.html#structureddeserialize>StructuredDeserialize</a>) serialized state.</p>

  <p>Pages can <a href=nav-history-apis.html#dom-history-pushstate id=session-history-entries:dom-history-pushstate>add</a> <a href=#serialized-state id=session-history-entries:serialized-state-3>serialized state</a> to the
  session history. These are then <a href=structured-data.html#structureddeserialize id=session-history-entries:structureddeserialize-2>deserialized</a> and <a href=indices.html#event-popstate id=session-history-entries:event-popstate>returned to the script</a> when the user (or script) goes back in the
  history, thus enabling authors to use the "navigation" metaphor even in one-page applications.</p>

  <div class=note>
   <p><a href=#serialized-state id=session-history-entries:serialized-state-4>Serialized state</a> is intended to be used for two main purposes: first, storing a
   preparsed description of the state in the <a id=session-history-entries:url-2 href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> so that in the simple case an author
   doesn't have to do the parsing (though one would still need the parsing for handling <a href=https://url.spec.whatwg.org/#concept-url id=session-history-entries:url-3 data-x-internal=url>URLs</a> passed around by users, so it's only a minor optimization). Second, so
   that the author can store state that one wouldn't store in the URL because it only applies to the
   current <code id=session-history-entries:document><a href=dom.html#document>Document</a></code> instance and it would have to be reconstructed if a new
   <code id=session-history-entries:document-2><a href=dom.html#document>Document</a></code> were opened.</p>

   <p>An example of the latter would be something like keeping track of the precise coordinate from
   which a popup <code id=session-history-entries:the-div-element><a href=grouping-content.html#the-div-element>div</a></code> was made to animate, so that if the user goes back, it can be made
   to animate to the same location. Or alternatively, it could be used to keep a pointer into a
   cache of data that would be fetched from the server based on the information in the
   <a id=session-history-entries:url-4 href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a>, so that when going back and forward, the information doesn't have to be fetched
   again.</p>
  </div>

  <hr>

  <p>A <dfn id=scroll-restoration-mode>scroll restoration mode</dfn> indicates whether the user agent should restore the
  persisted scroll position (if any) when traversing to an <a href=#session-history-entry id=session-history-entries:session-history-entry-2>entry</a>. A scroll restoration mode is one of the following:</p>

  <dl><dt>"<dfn data-dfn-for=ScrollRestoration id=dom-scrollrestoration-auto data-dfn-type=enum-value><code>auto</code></dfn>"<dd>The user agent is responsible for restoring the scroll position upon navigation.<dt>"<dfn data-dfn-for=ScrollRestoration id=dom-scrollrestoration-manual data-dfn-type=enum-value><code>manual</code></dfn>"<dd>The page is responsible for restoring the scroll position and the user agent does not
   attempt to do so automatically</dl>


  <h5 id=document-state><span class=secno>7.4.1.2</span> Document state<a href=#document-state class=self-link></a></h5>

  <p><dfn id=document-state-2>Document state</dfn> holds state inside a <a href=#session-history-entry id=document-state:session-history-entry>session history entry</a> regarding
  how to present and, if necessary, recreate, a <code id=document-state:document><a href=dom.html#document>Document</a></code>. It has:</p>

  <ul><li>
    <p>A <dfn id=document-state-document>document</dfn>, a <code id=document-state:document-2><a href=dom.html#document>Document</a></code> or null,
    initially null.</p>

    <div id=note-bfcache class=note><a href=#note-bfcache class=self-link></a>
     <p>When a history entry is <a href=document-sequences.html#nav-active-history-entry id=document-state:nav-active-history-entry>active</a>, it has a
     <code id=document-state:document-3><a href=dom.html#document>Document</a></code> in its <a href=#she-document-state id=document-state:she-document-state>document state</a>. However,
     when a <code id=document-state:document-4><a href=dom.html#document>Document</a></code> is not <a id=document-state:fully-active href=document-sequences.html#fully-active>fully active</a>, it's possible for it to be
     <a href=document-lifecycle.html#destroy-a-document id=document-state:destroy-a-document>destroyed</a> to free resources. In such cases, this
     <a href=#document-state-document id=document-state:document-state-document>document</a> item will be nulled out. The <a href=#she-url id=document-state:she-url>URL</a> and other data in the <a href=#session-history-entry id=document-state:session-history-entry-2>session history entry</a> and <a href=#she-document-state id=document-state:she-document-state-2>document state</a> is then used to bring a new
     <code id=document-state:document-5><a href=dom.html#document>Document</a></code> into being to take the place of the original, in the case where the user
     agent finds itself having to traverse to the entry.</p>

     <p>If the <code id=document-state:document-6><a href=dom.html#document>Document</a></code> is <em>not</em> <a href=document-lifecycle.html#destroy-a-document id=document-state:destroy-a-document-2>destroyed</a>, then during <a href=#traverse-the-history-by-a-delta id=document-state:traverse-the-history-by-a-delta>history
     traversal</a>, it can be <a href=#reactivate-a-document id=document-state:reactivate-a-document>reactivated</a>. The cache
     in which browsers store such <code id=document-state:document-7><a href=dom.html#document>Document</a></code>s is often called a <em>back-forward
     cache</em>, or <em>bfcache</em> (or perhaps <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=274784">"blazingly fast"</a> cache).</p>
    </div>
   <li><p id=she-policy-container>A <dfn id=document-state-history-policy-container>history
   policy container</dfn>, a <a id=document-state:policy-container href=browsers.html#policy-container>policy container</a> or null, initially null.<li><p>A <dfn id=document-state-request-referrer>request referrer</dfn>, which is "<code>no-referrer</code>", "<code>client</code>", or a <a id=document-state:url href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a>, initially
   "<code>client</code>".<li>
    <p>A <dfn id=document-state-request-referrer-policy>request referrer policy</dfn>, which
    is a <a id=document-state:referrer-policy href=https://w3c.github.io/webappsec-referrer-policy/#referrer-policy data-x-internal=referrer-policy>referrer policy</a>, initially the <a id=document-state:default-referrer-policy href=https://w3c.github.io/webappsec-referrer-policy/#default-referrer-policy data-x-internal=default-referrer-policy>default referrer policy</a>.</p>

    <p class=note>The <a href=#document-state-request-referrer-policy id=document-state:document-state-request-referrer-policy>request referrer
    policy</a> is distinct from the <a href=#document-state-history-policy-container id=document-state:document-state-history-policy-container>history policy container</a>'s <a href=browsers.html#policy-container-referrer-policy id=document-state:policy-container-referrer-policy>referrer policy</a>. The former is used for
    fetches <em>of</em> this document, whereas the latter controls fetches <em>by</em> this
    document.</p>
   <li>
    <p>An <dfn id=document-state-initiator-origin>initiator origin</dfn>, which is an
    <a id=document-state:concept-origin href=browsers.html#concept-origin>origin</a> or null, initially null.</p>
   <li>
    <p>An <dfn id=document-state-origin>origin</dfn>, which is an <a id=document-state:concept-origin-2 href=browsers.html#concept-origin>origin</a> or
    null, initially null.</p>

    <p class=note>This is the origin that we set "<code>about:</code>"-schemed
    <code id=document-state:document-8><a href=dom.html#document>Document</a></code>s' <a href=https://dom.spec.whatwg.org/#concept-document-origin id=document-state:concept-document-origin data-x-internal=concept-document-origin>origin</a> to. We store it
    here because it is also used when restoring these <code id=document-state:document-9><a href=dom.html#document>Document</a></code>s during traversal,
    since they are reconstructed locally without visiting the network. It is also used to compare
    the origin before and after the <a href=#session-history-entry id=document-state:session-history-entry-3>session history entry</a> is <a href="#attempt-to-populate-the-history-entry's-document" id="document-state:attempt-to-populate-the-history-entry's-document">repopulated</a>. If the origins change, the <a href=#document-state-nav-target-name id=document-state:document-state-nav-target-name>navigable target name</a> is cleared.</p>
   <li>
    <p>An <dfn id=document-state-about-base-url>about base URL</dfn>, which is a
    <a id=document-state:url-2 href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> or null, initially null.</p>

    <p class=note>This will be populated only for "<code>about:</code>"-schemed
    <code id=document-state:document-10><a href=dom.html#document>Document</a></code>s and will be the <a id=document-state:fallback-base-url href=urls-and-fetching.html#fallback-base-url>fallback base URL</a> for those
    <code id=document-state:document-11><a href=dom.html#document>Document</a></code>s. It is a snapshot of the initiator <code id=document-state:document-12><a href=dom.html#document>Document</a></code>'s <a id=document-state:document-base-url href=urls-and-fetching.html#document-base-url>document
    base URL</a>.</p>
   <li><p><dfn id=document-state-nested-histories>Nested histories</dfn>, a <a id=document-state:list href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a>
   of <a href=#nested-history id=document-state:nested-history>nested histories</a>, initially an empty
   <a id=document-state:list-2 href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a>.<li>
    <p>A <dfn id=document-state-resource>resource</dfn>, a string, <a href=#post-resource id=document-state:post-resource>POST resource</a>
    or null, initially null.</p>

    <p class=note>A string is treated as HTML. It's used to store the source of an <a href=iframe-embed-object.html#an-iframe-srcdoc-document id=document-state:an-iframe-srcdoc-document><code>iframe</code> <code>srcdoc</code> document</a>.</p>
   <li><p>A <dfn id=document-state-reload-pending>reload pending</dfn> boolean, initially
   false.<li><p>An <dfn id=document-state-ever-populated>ever populated</dfn> boolean, initially
   false.<li><p id=she-bc-name>A <dfn id=document-state-nav-target-name>navigable target
   name</dfn> string, initially the empty string.<li><p>A <dfn id=document-state-not-restored-reasons>not restored reasons</dfn>, a
   <a href=nav-history-apis.html#nrr-struct id=document-state:nrr-struct>not restored reasons</a> or null, initially null.</ul>

  <p>User agents may <a id=document-state:destroy-a-document-and-its-descendants href=document-lifecycle.html#destroy-a-document-and-its-descendants>destroy a document and its descendants</a> given the <a href=#document-state-document id=document-state:document-state-document-2>documents</a> of <a href=#document-state-2 id=document-state:document-state-2>document
  states</a> with non-null <a href=#document-state-document id=document-state:document-state-document-3>documents</a>, as long as
  the <code id=document-state:document-13><a href=dom.html#document>Document</a></code> is not <a id=document-state:fully-active-2 href=document-sequences.html#fully-active>fully active</a>.</p>

  <p>Apart from that restriction, this standard does not specify when user agents should destroy
  the <a href=#document-state-document id=document-state:document-state-document-4>document</a> stored in a <a href=#document-state-2 id=document-state:document-state-2-2>document
  state</a>, versus keeping it cached.</p>

  <hr>

  <p>A <dfn id=post-resource data-export="">POST resource</dfn> has:</p>

  <ul><li>
    <p>A <dfn data-dfn-for="POST resource" id=post-resource-request-body data-export="">request body</dfn>, a
    <a id=document-state:byte-sequence href=https://infra.spec.whatwg.org/#byte-sequence data-x-internal=byte-sequence>byte sequence</a> or failure.</p>

    <p>This is only ever accessed <a id=document-state:in-parallel href=infrastructure.html#in-parallel>in parallel</a>, so it doesn't need to be stored in
    memory. However, it must return the same <a id=document-state:byte-sequence-2 href=https://infra.spec.whatwg.org/#byte-sequence data-x-internal=byte-sequence>byte sequence</a> each time. If this isn't
    possible due to resources changing on disk, or if resources can no longer be accessed, then
    this must be set to failure.</p>
   <li><p>A <dfn data-dfn-for="POST resource" id=post-resource-request-content-type data-export="">request
   content-type</dfn>, which is `<code id=document-state:application/x-www-form-urlencoded><a data-x-internal=application/x-www-form-urlencoded href=https://url.spec.whatwg.org/#concept-urlencoded>application/x-www-form-urlencoded</a></code>`,
   `<code id=document-state:multipart/form-data><a href=indices.html#multipart/form-data>multipart/form-data</a></code>`, or `<code id=document-state:text/plain><a data-x-internal=text/plain href=https://www.rfc-editor.org/rfc/rfc2046#section-4.1.3>text/plain</a></code>`.</ul>

  <hr>

  <p>A <dfn id=nested-history>nested history</dfn> has:</p>

  <ul><li>
    <p>An <dfn id=nested-history-id>id</dfn>, a <a id=document-state:unique-internal-value href=common-microsyntaxes.html#unique-internal-value>unique internal value</a>.</p>

    <p class=note>This is used to associate the <a href=#nested-history id=document-state:nested-history-2>nested history</a> with a
    <a id=document-state:navigable href=document-sequences.html#navigable>navigable</a>.</p>
   <li><p><dfn id=nested-history-entries>Entries</dfn>, a <a id=document-state:list-3 href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a> of <a href=#session-history-entry id=document-state:session-history-entry-4>session history entries</a>.</ul>

  <p class=XXX>This will later contain ways to identify a child navigable across reloads.</p>

  <hr>

  <hr>

  <p>Several contiguous entries in a session history can share the same <a href=#she-document-state id=document-state:she-document-state-3>document state</a>. This can occur when the initial entry is
  reached via normal <a href=#navigate id=document-state:navigate>navigation</a>, and the following entry is added
  via <code id=document-state:dom-history-pushstate><a href=nav-history-apis.html#dom-history-pushstate>history.pushState()</a></code>. Or it can occur via <a href=#navigate-fragid id=document-state:navigate-fragid>navigation to a fragment</a>.</p>

  <p class=note>All entries that share the same <a href=#she-document-state id=document-state:she-document-state-4>document
  state</a> (and that are therefore merely different states of one particular document) are
  contiguous by construction.</p>

  <hr>

  <p>A <code id=document-state:document-14><a href=dom.html#document>Document</a></code> has a <dfn id=latest-entry>latest entry</dfn>, a <a href=#session-history-entry id=document-state:session-history-entry-5>session history entry</a> or
  null.</p>

  <p class=note>This is the entry that was most recently represented by a given
  <code id=document-state:document-15><a href=dom.html#document>Document</a></code>. A single <code id=document-state:document-16><a href=dom.html#document>Document</a></code> can represent many <a href=#session-history-entry id=document-state:session-history-entry-6>session history entries</a> over time, as many contiguous <a href=#session-history-entry id=document-state:session-history-entry-7>session history entries</a> can share the same <a href=#she-document-state id=document-state:she-document-state-5>document state</a> as explained above.</p>


  <h5 id=centralized-modifications-of-session-history><span class=secno>7.4.1.3</span> Centralized modifications of session history<a href=#centralized-modifications-of-session-history class=self-link></a></h5>

  <p>To maintain a single source of truth, all modifications to a <a id=centralized-modifications-of-session-history:traversable-navigable href=document-sequences.html#traversable-navigable>traversable
  navigable</a>'s <a href=document-sequences.html#tn-session-history-entries id=centralized-modifications-of-session-history:tn-session-history-entries>session history entries</a> need
  to be synchronized. This is especially important due to how session history is influenced by all
  of the descendant <a href=document-sequences.html#navigable id=centralized-modifications-of-session-history:navigable>navigables</a>, and thus by multiple <a href=webappapis.html#event-loop id=centralized-modifications-of-session-history:event-loop>event loops</a>. To accomplish this, we use the <a href=#session-history-traversal-parallel-queue id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue>session history
  traversal parallel queue</a> structure.</p>

  <p id=session-history-traversal-queue>A <dfn id=session-history-traversal-parallel-queue>session history traversal parallel queue</dfn> is
  very similar to a <a id=centralized-modifications-of-session-history:parallel-queue href=infrastructure.html#parallel-queue>parallel queue</a>. It has an <dfn id=session-history-traversal-parallel-queue-algorithm-set>algorithm set</dfn>, an <a href=https://infra.spec.whatwg.org/#ordered-set id=centralized-modifications-of-session-history:set data-x-internal=set>ordered set</a>.</p>

  <p>The <a href=https://infra.spec.whatwg.org/#list-item id=centralized-modifications-of-session-history:list-item data-x-internal=list-item>items</a> in a <a href=#session-history-traversal-parallel-queue id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue-2>session history traversal parallel
  queue</a>'s <a href=#session-history-traversal-parallel-queue-algorithm-set id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue-algorithm-set>algorithm
  set</a> are either algorithm steps, or <dfn id=session-history-traversal-parallel-queue-sync-nav-steps>synchronous navigation
  steps</dfn>, which are a particular brand of algorithm steps involving a <dfn id=session-history-traversal-parallel-queue-sync-nav-steps-target-nav>target
  navigable</dfn> (a <a id=centralized-modifications-of-session-history:navigable-2 href=document-sequences.html#navigable>navigable</a>).</p>

  <p>To <dfn id=tn-append-session-history-traversal-steps>append session history traversal
  steps</dfn> to a <a id=centralized-modifications-of-session-history:traversable-navigable-2 href=document-sequences.html#traversable-navigable>traversable navigable</a> <var>traversable</var> given algorithm steps
  <var>steps</var>, <a href=https://infra.spec.whatwg.org/#list-append id=centralized-modifications-of-session-history:list-append data-x-internal=list-append>append</a> <var>steps</var> to
  <var>traversable</var>'s <a href=document-sequences.html#tn-session-history-traversal-queue id=centralized-modifications-of-session-history:tn-session-history-traversal-queue>session history
  traversal queue</a>'s <a href=#session-history-traversal-parallel-queue-algorithm-set id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue-algorithm-set-2>algorithm set</a>.</p>

  <p>To <dfn id=tn-append-session-history-sync-nav-steps>append session history synchronous
  navigation steps</dfn> involving a <a id=centralized-modifications-of-session-history:navigable-3 href=document-sequences.html#navigable>navigable</a> <var>targetNavigable</var> to a
  <a id=centralized-modifications-of-session-history:traversable-navigable-3 href=document-sequences.html#traversable-navigable>traversable navigable</a> <var>traversable</var> given algorithm steps <var>steps</var>,
  <a href=https://infra.spec.whatwg.org/#list-append id=centralized-modifications-of-session-history:list-append-2 data-x-internal=list-append>append</a> <var>steps</var> as <a href=#session-history-traversal-parallel-queue-sync-nav-steps id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue-sync-nav-steps>synchronous navigation
  steps</a> targeting <a href=#session-history-traversal-parallel-queue-sync-nav-steps-target-nav id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue-sync-nav-steps-target-nav>target
  navigable</a> <var>targetNavigable</var> to <var>traversable</var>'s <a href=document-sequences.html#tn-session-history-traversal-queue id=centralized-modifications-of-session-history:tn-session-history-traversal-queue-2>session history traversal queue</a>'s <a href=#session-history-traversal-parallel-queue-algorithm-set id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue-algorithm-set-3>algorithm set</a>.</p>

  <p id=session-history-event-loop>To <dfn id=starting-a-new-session-history-traversal-parallel-queue>start a new session history traversal parallel queue</dfn>:</p>

  <ol><li><p>Let <var>sessionHistoryTraversalQueue</var> be a new <a href=#session-history-traversal-parallel-queue id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue-3>session history traversal
   parallel queue</a>.<li>
    <p>Run the following steps <a id=centralized-modifications-of-session-history:in-parallel href=infrastructure.html#in-parallel>in parallel</a>:</p>

    <ol><li>
      <p>While true:</p>

      <ol><li><p>If <var>sessionHistoryTraversalQueue</var>'s <a href=#session-history-traversal-parallel-queue-algorithm-set id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue-algorithm-set-4>algorithm set</a> is
       empty, then <a id=centralized-modifications-of-session-history:continue href=https://infra.spec.whatwg.org/#iteration-continue data-x-internal=continue>continue</a>.<li><p>Let <var>steps</var> be the result of <a href=https://infra.spec.whatwg.org/#queue-dequeue id=centralized-modifications-of-session-history:dequeue data-x-internal=dequeue>dequeuing</a> from
       <var>sessionHistoryTraversalQueue</var>'s <a href=#session-history-traversal-parallel-queue-algorithm-set id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue-algorithm-set-5>algorithm
       set</a>.<li><p>Run <var>steps</var>.</ol>
     </ol>
   <li><p>Return <var>sessionHistoryTraversalQueue</var>.</ol>

  <p id=sync-navigation-steps-queue-jumping-examples><a href=#session-history-traversal-parallel-queue-sync-nav-steps id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue-sync-nav-steps-2>Synchronous navigation
  steps</a> are tagged in the <a href=#session-history-traversal-parallel-queue-algorithm-set id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue-algorithm-set-6>algorithm set</a> to allow
  them to conditionally "jump the queue". This is handled <a href=#sync-navigations-jump-queue>within apply the history step</a>.</p>

  <div id=example-sync-navigation-steps-queue-jumping-basic class=example><a href=#example-sync-navigation-steps-queue-jumping-basic class=self-link></a>
   <p>Imagine the joint session history depicted by this <a id=centralized-modifications-of-session-history:jake-diagram href=document-sequences.html#jake-diagram>Jake diagram</a>:</p>

   
   <table class=jake-diagram><thead><tr><td><th class=step>0<th class="step current">1<tbody><tr><th><code>top</code><td colspan=1 class=doc-0>/a<td colspan=1 class="doc-1 current">/b</table>

   <p>And the following code runs at the top level:</p>

   <pre><code class='js'>history<c- p>.</c->back<c- p>();</c->
location<c- p>.</c->href <c- o>=</c-> <c- t>&apos;#foo&apos;</c-><c- p>;</c-></code></pre>

   <p>The desired result is:</p>

   
   <table class=jake-diagram><thead><tr><td><th class="step current">0<th class=step>1<th class=step>2<tbody><tr><th><code>top</code><td colspan=1 class="doc-0 current">/a<td colspan=1 class="doc-1 next-is-same-doc">/b<td colspan=1 class="doc-1 prev-is-same-doc">/b#foo</table>

   <p>This isn't straightforward, as the sync navigation wins the race in terms of being
   observable, whereas the traversal wins the race in terms of queuing steps on the <a href=#session-history-traversal-parallel-queue id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue-4>session
   history traversal parallel queue</a>. To achieve this result, the following happens:</p>

   <ol><li><p><code id=centralized-modifications-of-session-history:dom-history-back><a href=nav-history-apis.html#dom-history-back>history.back()</a></code> <a href=#tn-append-session-history-traversal-steps id=centralized-modifications-of-session-history:tn-append-session-history-traversal-steps>appends steps</a> intended to traverse by
    a delta of −1.<li><p><code id=centralized-modifications-of-session-history:dom-location-href><a href=nav-history-apis.html#dom-location-href>location.href = '#foo'</a></code> synchronously changes the
    <a href=document-sequences.html#nav-active-history-entry id=centralized-modifications-of-session-history:nav-active-history-entry>active session history entry</a> entry to a
    newly-created one, with the URL <code>/b#foo</code>, and <a href=#tn-append-session-history-sync-nav-steps id=centralized-modifications-of-session-history:tn-append-session-history-sync-nav-steps>appends synchronous steps</a> to notify
    the central source of truth about that new entry. Note that this does <em>not</em> yet update
    the <a href=document-sequences.html#nav-current-history-entry id=centralized-modifications-of-session-history:nav-current-history-entry>current session history entry</a>, <a href=document-sequences.html#tn-current-session-history-step id=centralized-modifications-of-session-history:tn-current-session-history-step>current session history step</a>, or the <a href=document-sequences.html#tn-session-history-entries id=centralized-modifications-of-session-history:tn-session-history-entries-2>session history entries</a> list; those updates cannot
    be done synchronously, and instead must be done as part of the queued steps.<li>
     <p>On the <a href=#session-history-traversal-parallel-queue id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue-5>session history traversal parallel queue</a>, the steps queued by <code id=centralized-modifications-of-session-history:dom-history-back-2><a href=nav-history-apis.html#dom-history-back>history.back()</a></code> run:</p>

     <ol><li><p>The target history step is determined to be 0: the <a href=document-sequences.html#tn-current-session-history-step id=centralized-modifications-of-session-history:tn-current-session-history-step-2>current session history step</a> (i.e., 1) plus
      the intended delta of −1.<li>
       <p>We enter the main <a href=#apply-the-history-step id=centralized-modifications-of-session-history:apply-the-history-step>apply the history step</a> algorithm.</p>

       <p>The entry at step 0, for the <code>/a</code> URL, has its <a href=#she-document id=centralized-modifications-of-session-history:she-document>document</a> <a href="#attempt-to-populate-the-history-entry's-document" id="centralized-modifications-of-session-history:attempt-to-populate-the-history-entry's-document">populated</a>.</p>

       <p>Meanwhile, the queue is checked for <a href=#session-history-traversal-parallel-queue-sync-nav-steps id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue-sync-nav-steps-3>synchronous navigation
       steps</a>. The steps queued by the <code id=centralized-modifications-of-session-history:dom-location-href-2><a href=nav-history-apis.html#dom-location-href>location.href</a></code>
       setter now run, and block the traversal from performing effects beyond document population
       (such as, unloading documents and switching active history entries) until they are finished.
       Those steps cause the following to happen:</p>

       <ol><li><p>The entry with URL <code>/b#foo</code> is added, with its <a href=#she-step id=centralized-modifications-of-session-history:she-step>step</a> determined to be 2: the <a href=document-sequences.html#tn-current-session-history-step id=centralized-modifications-of-session-history:tn-current-session-history-step-3>current session history step</a> (i.e., 1) plus
        1.<li><p>We fully switch to that newly added entry, including a nested call to <a href=#apply-the-history-step id=centralized-modifications-of-session-history:apply-the-history-step-2>apply
        the history step</a>. This ultimately results in <a href=#update-document-for-history-step-application id=centralized-modifications-of-session-history:update-document-for-history-step-application>updating the document</a> by dispatching events like <code id=centralized-modifications-of-session-history:event-hashchange><a href=indices.html#event-hashchange>hashchange</a></code>.</ol>

       <p>Only once that is all complete, and the <code>/a</code> history entry has been
       fully populated with a <a href=#she-document id=centralized-modifications-of-session-history:she-document-2>document</a>, do we move on with
       applying the history step given the target step of 0.</p>

       <p>At this point, the <code id=centralized-modifications-of-session-history:document><a href=dom.html#document>Document</a></code> with URL <code>/b#foo</code> <a href=document-lifecycle.html#unload-a-document id=centralized-modifications-of-session-history:unload-a-document>unloads</a>, and we finish moving to our target history step
       0, which makes the entry with URL <code>/a</code> become the <a href=document-sequences.html#nav-active-history-entry id=centralized-modifications-of-session-history:nav-active-history-entry-2>active session history entry</a> and 0 become the <a href=document-sequences.html#tn-current-session-history-step id=centralized-modifications-of-session-history:tn-current-session-history-step-4>current session history step</a>.</p>
      </ol>
    </ol>
  </div>

  <div id=example-sync-navigation-steps-queue-jumping-complex class=example><a href=#example-sync-navigation-steps-queue-jumping-complex class=self-link></a>
   <p>Here is another more complex example, involving races between populating two different
   <code id=centralized-modifications-of-session-history:the-iframe-element><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code>s, and a synchronous navigation once one of those iframes loads. We start
   with this setup:</p>

   
   <table class=jake-diagram><thead><tr><td><th class=step>0<th class=step>1<th class="step current">2<tbody><tr><th><code>top</code><td colspan=3 class="doc-0 current">/t<tr><th><code>frames[0]</code><td colspan=1 class=doc-1>/i-0-a<td colspan=2 class="doc-2 current">/i-0-b<tr><th><code>frames[1]</code><td colspan=2 class=doc-3>/i-1-a<td colspan=1 class="doc-4 current">/i-1-b</table>

   <p>and then call <code id=centralized-modifications-of-session-history:dom-history-go><a href=nav-history-apis.html#dom-history-go>history.go(-2)</a></code>. The following then
   occurs:</p>

   <ol><li>
     <p><code id=centralized-modifications-of-session-history:dom-history-go-2><a href=nav-history-apis.html#dom-history-go>history.go(-2)</a></code> <a href=#tn-append-session-history-traversal-steps id=centralized-modifications-of-session-history:tn-append-session-history-traversal-steps-2>appends steps</a> intended to traverse
     by a delta of −2. Once those steps run:</p>

     <ol><li><p>The target step is determined to be 2 + (−2) = 0.<li>
       <p>In parallel, the fetches are made to <a href="#attempt-to-populate-the-history-entry's-document" id="centralized-modifications-of-session-history:attempt-to-populate-the-history-entry's-document-2">populate</a> the two iframes, fetching <code>/i-0-a</code>
       and <code>/i-1-a</code> respectively.</p>

       <p>Meanwhile, the queue is checked for <a href=#session-history-traversal-parallel-queue-sync-nav-steps id=centralized-modifications-of-session-history:session-history-traversal-parallel-queue-sync-nav-steps-4>synchronous navigation
       steps</a>. There aren't any right now.</p>
      <li><p>In the fetch race, the fetch for <code>/i-0-a</code> wins. We proceed onward
      to finish all of <a href=#apply-the-history-step id=centralized-modifications-of-session-history:apply-the-history-step-3>apply the history step</a>'s work for how the traversal impacts the
      <code>frames[0]</code> <a id=centralized-modifications-of-session-history:navigable-4 href=document-sequences.html#navigable>navigable</a>, including updating its <a href=document-sequences.html#nav-active-history-entry id=centralized-modifications-of-session-history:nav-active-history-entry-3>active session history entry</a> to the entry with URL
      <code>/i-0-a</code>.<li>
       <p>Before the fetch for <code>/i-1-a</code> finishes, we reach the point where
       <a href=#scripts-may-run-for-the-newly-created-document id=centralized-modifications-of-session-history:scripts-may-run-for-the-newly-created-document>scripts may run for the newly-created document</a> in the <code>frames[0]</code> <a id=centralized-modifications-of-session-history:navigable-5 href=document-sequences.html#navigable>navigable</a>'s <a href=document-sequences.html#nav-document id=centralized-modifications-of-session-history:nav-document>active
       document</a>. Some such script does run:</p>

       <pre><code class='js'>location<c- p>.</c->href <c- o>=</c-> <c- t>&apos;#foo&apos;</c-></code></pre>

       <p>This synchronously changes the <code>frames[0]</code> navigable's <a href=document-sequences.html#nav-active-history-entry id=centralized-modifications-of-session-history:nav-active-history-entry-4>active session history entry</a> entry to a
       newly-created one, with the URL <code>/i-0-a#foo</code>, and <a href=#tn-append-session-history-sync-nav-steps id=centralized-modifications-of-session-history:tn-append-session-history-sync-nav-steps-2>appends synchronous steps</a> to notify
       the central source of truth about that new entry.</p>

       <p>Unlike in the <a href=#example-sync-navigation-steps-queue-jumping-basic>previous
       example</a>, these synchronous steps do <em>not</em> "jump the queue" and update the <a href=document-sequences.html#traversable-navigable id=centralized-modifications-of-session-history:traversable-navigable-4>traversable</a> before we finish the fetch for <code>/i-1-a</code>. This is because the navigable in question, <code>frames[0]</code>, has already been altered as part of the traversal, so we know
       that with the <a href=document-sequences.html#tn-current-session-history-step id=centralized-modifications-of-session-history:tn-current-session-history-step-5>current session history
       step</a> being 2, adding the new entry as a step 3 doesn't make sense.</p>
      <li><p>Once the fetch for <code>/i-1-a</code> finally finishes, we proceed to finish
      updating the <code>frames[1]</code> <a id=centralized-modifications-of-session-history:navigable-6 href=document-sequences.html#navigable>navigable</a> for the traversal,
      including updating its <a href=document-sequences.html#nav-active-history-entry id=centralized-modifications-of-session-history:nav-active-history-entry-5>active session history
      entry</a> to the entry with URL <code>/i-1-a</code>.<li><p>Now that both navigables have finished processing the traversal, we update the <a href=document-sequences.html#tn-current-session-history-step id=centralized-modifications-of-session-history:tn-current-session-history-step-6>current session history step</a> to the target
      step of 0.</ol>
    <li>
     <p>Now we can process the steps that were queued for the synchronous navigation:</p>

     <ol><li><p>The <code>/i-0-a#foo</code> entry is added, with its <a href=#she-step id=centralized-modifications-of-session-history:she-step-2>step</a> determined to be 1: the <a href=document-sequences.html#tn-current-session-history-step id=centralized-modifications-of-session-history:tn-current-session-history-step-7>current session history step</a> (i.e., 0) plus
      1. This also <a href=#clear-the-forward-session-history id=centralized-modifications-of-session-history:clear-the-forward-session-history>clears existing forward
      history</a>.<li><p>We fully switch to that newly added entry, including calling <a href=#apply-the-history-step id=centralized-modifications-of-session-history:apply-the-history-step-4>apply the history
      step</a>. This ultimately results in <a href=#update-document-for-history-step-application id=centralized-modifications-of-session-history:update-document-for-history-step-application-2>updating the document</a> by dispatching events like <code id=centralized-modifications-of-session-history:event-hashchange-2><a href=indices.html#event-hashchange>hashchange</a></code>, as well as updating the <a href=document-sequences.html#tn-current-session-history-step id=centralized-modifications-of-session-history:tn-current-session-history-step-8>current session history step</a> to the target
      step of 1.</ol>
    </ol>

   <p>The end result is:</p>

   
   <table class=jake-diagram><thead><tr><td><th class=step>0<th class="step current">1<tbody><tr><th><code>top</code><td colspan=2 class="doc-0 current">/t<tr><th><code>frames[0]</code><td colspan=1 class="doc-1 next-is-same-doc">/i-0-a<td colspan=1 class="doc-1 current prev-is-same-doc">/i-0-a#foo<tr><th><code>frames[1]</code><td colspan=2 class="doc-3 current">/i-1-a</table>
  </div>


  <h5 id=low-level-operations-on-session-history><span class=secno>7.4.1.4</span> Low-level operations on session history<a href=#low-level-operations-on-session-history class=self-link></a></h5>

  <p>This section contains a miscellaneous grab-bag of operations that we perform throughout the
  standard when manipulating session history. The best way to get a sense of what they do is to
  look at their call sites.</p>

  <p>To <dfn id=getting-session-history-entries>get session history entries</dfn> of a
  <a id=low-level-operations-on-session-history:navigable href=document-sequences.html#navigable>navigable</a> <var>navigable</var>:</p>

  <ol><li><p>Let <var>traversable</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-traversable id=low-level-operations-on-session-history:nav-traversable>traversable navigable</a>.<li><p><a id=low-level-operations-on-session-history:assert href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: this is running within <var>traversable</var>'s <a href=document-sequences.html#tn-session-history-traversal-queue id=low-level-operations-on-session-history:tn-session-history-traversal-queue>session history traversal queue</a>.<li><p>If <var>navigable</var> is <var>traversable</var>, return <var>traversable</var>'s <a href=document-sequences.html#tn-session-history-entries id=low-level-operations-on-session-history:tn-session-history-entries>session history entries</a>.<li><p>Let <var>docStates</var> be an empty <a href=https://infra.spec.whatwg.org/#ordered-set id=low-level-operations-on-session-history:set data-x-internal=set>ordered set</a> of <a href=#document-state-2 id=low-level-operations-on-session-history:document-state-2>document states</a>.<li><p>For each <var>entry</var> of <var>traversable</var>'s <a href=document-sequences.html#tn-session-history-entries id=low-level-operations-on-session-history:tn-session-history-entries-2>session history entries</a>, <a href=https://infra.spec.whatwg.org/#set-append id=low-level-operations-on-session-history:set-append data-x-internal=set-append>append</a> <var>entry</var>'s <a href=#she-document-state id=low-level-operations-on-session-history:she-document-state>document state</a>
   to <var>docStates</var>.<li>
    <p><a href=https://infra.spec.whatwg.org/#list-iterate id=low-level-operations-on-session-history:list-iterate data-x-internal=list-iterate>For each</a> <var>docState</var> of <var>docStates</var>:</p>

    <ol><li>
      <p><a href=https://infra.spec.whatwg.org/#list-iterate id=low-level-operations-on-session-history:list-iterate-2 data-x-internal=list-iterate>For each</a> <var>nestedHistory</var> of
      <var>docState</var>'s <a href=#document-state-nested-histories id=low-level-operations-on-session-history:document-state-nested-histories>nested
      histories</a>:</p>

      <ol><li><p>If <var>nestedHistory</var>'s <a href=#nested-history-id id=low-level-operations-on-session-history:nested-history-id>id</a> equals
       <var>navigable</var>'s <a href=document-sequences.html#nav-id id=low-level-operations-on-session-history:nav-id>id</a>, return <var>nestedHistory</var>'s
       <a href=#nested-history-entries id=low-level-operations-on-session-history:nested-history-entries>entries</a>.<li><p>For each <var>entry</var> of <var>nestedHistory</var>'s <a href=#nested-history-entries id=low-level-operations-on-session-history:nested-history-entries-2>entries</a>, <a href=https://infra.spec.whatwg.org/#set-append id=low-level-operations-on-session-history:set-append-2 data-x-internal=set-append>append</a>
       <var>entry</var>'s <a href=#she-document-state id=low-level-operations-on-session-history:she-document-state-2>document state</a> to
       <var>docStates</var>.</ol>
     </ol>
   <li><p><a id=low-level-operations-on-session-history:assert-2 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: this step is not reached.</ol>

  <p>To <dfn id=getting-session-history-entries-for-the-navigation-api>get session history
  entries for the navigation API</dfn> of a <a id=low-level-operations-on-session-history:navigable-2 href=document-sequences.html#navigable>navigable</a> <var>navigable</var> given an
  integer <var>targetStep</var>:</p>

  <ol><li><p>Let <var>rawEntries</var> be the result of <a href=#getting-session-history-entries id=low-level-operations-on-session-history:getting-session-history-entries>getting session history entries</a>
   for <var>navigable</var>.<li><p>Let <var>entriesForNavigationAPI</var> be a new empty <a id=low-level-operations-on-session-history:list href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a>.<li>
    <p>Let <var>startingIndex</var> be the index of the <a href=#session-history-entry id=low-level-operations-on-session-history:session-history-entry>session history entry</a> in
    <var>rawEntries</var> who has the greatest <a href=#she-step id=low-level-operations-on-session-history:she-step>step</a> less than or
    equal to <var>targetStep</var>.</p>

    <p class=note>See <a href=#example-getting-the-target-history-entry>this example</a> to
    understand why it's the greatest step less than or equal to <var>targetStep</var>.</p>
   <li><p><a href=https://infra.spec.whatwg.org/#list-append id=low-level-operations-on-session-history:list-append data-x-internal=list-append>Append</a> <var>rawEntries</var>[<var>startingIndex</var>]
   to <var>entriesForNavigationAPI</var>.<li><p>Let <var>startingOrigin</var> be <var>rawEntries</var>[<var>startingIndex</var>]'s <a href=#she-document-state id=low-level-operations-on-session-history:she-document-state-3>document state</a>'s <a href=#document-state-origin id=low-level-operations-on-session-history:document-state-origin>origin</a>.<li><p>Let <var>i</var> be <var>startingIndex</var> − 1.<li>
    <p>While <var>i</var> > 0:</p>

    <ol><li><p>If <var>rawEntries</var>[<var>i</var>]'s <a href=#she-document-state id=low-level-operations-on-session-history:she-document-state-4>document
     state</a>'s <a href=#document-state-origin id=low-level-operations-on-session-history:document-state-origin-2>origin</a> is not <a id=low-level-operations-on-session-history:same-origin href=browsers.html#same-origin>same
     origin</a> with <var>startingOrigin</var>, then <a id=low-level-operations-on-session-history:break href=https://infra.spec.whatwg.org/#iteration-break data-x-internal=break>break</a>.<li><p><a href=https://infra.spec.whatwg.org/#list-prepend id=low-level-operations-on-session-history:list-prepend data-x-internal=list-prepend>Prepend</a> <var>rawEntries</var>[<var>i</var>] to
     <var>entriesForNavigationAPI</var>.<li><p>Set <var>i</var> to <var>i</var> − 1.</ol>
   <li><p>Set <var>i</var> to <var>startingIndex</var> + 1.<li>
    <p>While <var>i</var> &lt; <var>rawEntries</var>'s <a href=https://infra.spec.whatwg.org/#list-size id=low-level-operations-on-session-history:list-size data-x-internal=list-size>size</a>:</p>

    <ol><li><p>If <var>rawEntries</var>[<var>i</var>]'s <a href=#she-document-state id=low-level-operations-on-session-history:she-document-state-5>document
     state</a>'s <a href=#document-state-origin id=low-level-operations-on-session-history:document-state-origin-3>origin</a> is not <a id=low-level-operations-on-session-history:same-origin-2 href=browsers.html#same-origin>same
     origin</a> with <var>startingOrigin</var>, then <a id=low-level-operations-on-session-history:break-2 href=https://infra.spec.whatwg.org/#iteration-break data-x-internal=break>break</a>.<li><p><a href=https://infra.spec.whatwg.org/#list-append id=low-level-operations-on-session-history:list-append-2 data-x-internal=list-append>Append</a> <var>rawEntries</var>[<var>i</var>] to
     <var>entriesForNavigationAPI</var>.<li><p>Set <var>i</var> to <var>i</var> + 1.</ol>
   <li><p>Return <var>entriesForNavigationAPI</var>.</ol>

  <p>To <dfn id=clear-the-forward-session-history>clear the forward session history</dfn> of a <a id=low-level-operations-on-session-history:traversable-navigable href=document-sequences.html#traversable-navigable>traversable navigable</a>
  <var>navigable</var>:</p>

  <ol><li><p><a id=low-level-operations-on-session-history:assert-3 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: this is running within <var>navigable</var>'s <a href=document-sequences.html#tn-session-history-traversal-queue id=low-level-operations-on-session-history:tn-session-history-traversal-queue-2>session history traversal queue</a>.<li><p>Let <var>step</var> be the <var>navigable</var>'s <a href=document-sequences.html#tn-current-session-history-step id=low-level-operations-on-session-history:tn-current-session-history-step>current session history step</a>.<li><p>Let <var>entryLists</var> be the <a href=https://infra.spec.whatwg.org/#ordered-set id=low-level-operations-on-session-history:set-2 data-x-internal=set>ordered set</a> «
   <var>navigable</var>'s <a href=document-sequences.html#tn-session-history-entries id=low-level-operations-on-session-history:tn-session-history-entries-3>session history entries</a>
   ».<li>
    <p><a href=https://infra.spec.whatwg.org/#list-iterate id=low-level-operations-on-session-history:list-iterate-3 data-x-internal=list-iterate>For each</a> <var>entryList</var> of
    <var>entryLists</var>:</p>

    <ol><li><p><a href=https://infra.spec.whatwg.org/#list-remove id=low-level-operations-on-session-history:list-remove data-x-internal=list-remove>Remove</a> every <a href=#session-history-entry id=low-level-operations-on-session-history:session-history-entry-2>session history entry</a> from
     <var>entryList</var> that has a <a href=#she-step id=low-level-operations-on-session-history:she-step-2>step</a> greater than
     <var>step</var>.<li>
      <p><a href=https://infra.spec.whatwg.org/#list-iterate id=low-level-operations-on-session-history:list-iterate-4 data-x-internal=list-iterate>For each</a> <var>entry</var> of <var>entryList</var>:</p>

      <ol><li><p><a href=https://infra.spec.whatwg.org/#list-iterate id=low-level-operations-on-session-history:list-iterate-5 data-x-internal=list-iterate>For each</a> <var>nestedHistory</var> of
       <var>entry</var>'s <a href=#she-document-state id=low-level-operations-on-session-history:she-document-state-6>document state</a>'s <a href=#document-state-nested-histories id=low-level-operations-on-session-history:document-state-nested-histories-2>nested histories</a>, <a href=https://infra.spec.whatwg.org/#set-append id=low-level-operations-on-session-history:set-append-3 data-x-internal=set-append>append</a> <var>nestedHistory</var>'s <a href=#nested-history-entries id=low-level-operations-on-session-history:nested-history-entries-3>entries list</a> to <var>entryLists</var>.</ol>
     </ol>
   </ol>

  <p>To <dfn id=getting-all-used-history-steps>get all used history steps</dfn> that are part
  of <a id=low-level-operations-on-session-history:traversable-navigable-2 href=document-sequences.html#traversable-navigable>traversable navigable</a> <var>traversable</var>:</p>

  <ol><li><p><a id=low-level-operations-on-session-history:assert-4 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: this is running within <var>traversable</var>'s <a href=document-sequences.html#tn-session-history-traversal-queue id=low-level-operations-on-session-history:tn-session-history-traversal-queue-3>session history traversal queue</a>.<li><p>Let <var>steps</var> be an empty <a href=https://infra.spec.whatwg.org/#ordered-set id=low-level-operations-on-session-history:set-3 data-x-internal=set>ordered set</a> of non-negative
   integers.<li><p>Let <var>entryLists</var> be the <a href=https://infra.spec.whatwg.org/#ordered-set id=low-level-operations-on-session-history:set-4 data-x-internal=set>ordered set</a> «
   <var>traversable</var>'s <a href=document-sequences.html#tn-session-history-entries id=low-level-operations-on-session-history:tn-session-history-entries-4>session history
   entries</a> ».<li>
    <p><a href=https://infra.spec.whatwg.org/#list-iterate id=low-level-operations-on-session-history:list-iterate-6 data-x-internal=list-iterate>For each</a> <var>entryList</var> of
    <var>entryLists</var>:</p>

    <ol><li>
      <p><a href=https://infra.spec.whatwg.org/#list-iterate id=low-level-operations-on-session-history:list-iterate-7 data-x-internal=list-iterate>For each</a> <var>entry</var> of <var>entryList</var>:</p>

      <ol><li><p><a href=https://infra.spec.whatwg.org/#set-append id=low-level-operations-on-session-history:set-append-4 data-x-internal=set-append>Append</a> <var>entry</var>'s <a href=#she-step id=low-level-operations-on-session-history:she-step-3>step</a> to <var>steps</var>.<li><p><a href=https://infra.spec.whatwg.org/#list-iterate id=low-level-operations-on-session-history:list-iterate-8 data-x-internal=list-iterate>For each</a> <var>nestedHistory</var> of
       <var>entry</var>'s <a href=#she-document-state id=low-level-operations-on-session-history:she-document-state-7>document state</a>'s <a href=#document-state-nested-histories id=low-level-operations-on-session-history:document-state-nested-histories-3>nested histories</a>, <a href=https://infra.spec.whatwg.org/#set-append id=low-level-operations-on-session-history:set-append-5 data-x-internal=set-append>append</a> <var>nestedHistory</var>'s <a href=#nested-history-entries id=low-level-operations-on-session-history:nested-history-entries-4>entries list</a> to <var>entryLists</var>.</ol>
     </ol>
   <li><p>Return <var>steps</var>, <a href=https://infra.spec.whatwg.org/#list-sort-in-ascending-order id=low-level-operations-on-session-history:list-sort data-x-internal=list-sort>sorted</a>.</ol>


  <h4 id=navigating-across-documents><span class=secno>7.4.2</span> <span id=browsing-the-web></span>Navigation<a href=#navigating-across-documents class=self-link></a></h4>

  <p>Certain actions cause a <a id=navigating-across-documents:navigable href=document-sequences.html#navigable>navigable</a> to <i id=navigating-across-documents:navigate><a href=#navigate>navigate</a></i> to
  a new resource.</p>

  <p class=example>For example, <a href=links.html#following-hyperlinks-2 id=navigating-across-documents:following-hyperlinks-2>following a hyperlink</a>,
  <a href=form-control-infrastructure.html#concept-form-submit id=navigating-across-documents:concept-form-submit>form submission</a>, and the <code id=navigating-across-documents:dom-open><a href=nav-history-apis.html#dom-open>window.open()</a></code> and <code id=navigating-across-documents:dom-location-assign><a href=nav-history-apis.html#dom-location-assign>location.assign()</a></code> methods can all cause navigation.</p>

  <div id=note-meaning-of-navigate class=note><a href=#note-meaning-of-navigate class=self-link></a>
   <p>Although in this standard the word "navigation" refers specifically to the
   <a href=#navigate id=navigating-across-documents:navigate-2>navigate</a> algorithm, this doesn't always line up with web developer or user
   perceptions. For example:</p>

   <ul><li><p>The <a href=#url-and-history-update-steps id=navigating-across-documents:url-and-history-update-steps>URL and history update steps</a> are often used during so-called
    "single-page app navigations" or "same-document navigations", but they do not trigger the
    <a href=#navigate id=navigating-across-documents:navigate-3>navigate</a> algorithm.<li><p><a href=#reload id=navigating-across-documents:reload>Reloads</a> and <a href=#traverse-the-history-by-a-delta id=navigating-across-documents:traverse-the-history-by-a-delta>traversals</a> are sometimes talked about as a type of navigation, since all three
    will often <a href="#attempt-to-populate-the-history-entry's-document" id="navigating-across-documents:attempt-to-populate-the-history-entry's-document">attempt to populate the history entry's document</a> and thus could perform
    navigational fetches. See, e.g., the APIs exposed <cite>Navigation Timing</cite>. But they have
    their own entry point algorithms, separate from the <a href=#navigate id=navigating-across-documents:navigate-4>navigate</a> algorithm.
    <a href=references.html#refsNAVIGATIONTIMING>[NAVIGATIONTIMING]</a><li><p>Although <a href=#navigate-fragid id=navigating-across-documents:navigate-fragid>fragment navigations</a> are always done
    through the <a href=#navigate id=navigating-across-documents:navigate-5>navigate</a> algorithm, a user might perceive them as more like jumping
    around a single page, than as a true navigation.</ul>
  </div>


  <h5 id=navigation-supporting-concepts><span class=secno>7.4.2.1</span> Supporting concepts<a href=#navigation-supporting-concepts class=self-link></a></h5>

  <p>Before we can jump into the <a href=#navigate id=navigation-supporting-concepts:navigate>navigation algorithm</a> itself, we
  need to establish several important structures that it uses.</p>

  <p>The <dfn id=source-snapshot-params>source snapshot params</dfn> <a id=navigation-supporting-concepts:struct href=https://infra.spec.whatwg.org/#struct data-x-internal=struct>struct</a> is used to capture data from a
  <code id=navigation-supporting-concepts:document><a href=dom.html#document>Document</a></code> initiating a navigation. It is snapshotted at the beginning of a navigation
  and used throughout the navigation's lifetime. It has the following <a href=https://infra.spec.whatwg.org/#struct-item id=navigation-supporting-concepts:struct-item data-x-internal=struct-item>items</a>:</p>

  <dl><dt><dfn id=source-snapshot-params-activation>has transient activation</dfn><dd>a boolean<dt><dfn id=source-snapshot-params-sandbox>sandboxing flags</dfn><dd>a <a id=navigation-supporting-concepts:sandboxing-flag-set href=browsers.html#sandboxing-flag-set>sandboxing flag set</a><dt><dfn id=source-snapshot-params-download>allows downloading</dfn><dd>a boolean<dt><dfn id=source-snapshot-params-client>fetch client</dfn><dd>an <a id=navigation-supporting-concepts:environment-settings-object href=webappapis.html#environment-settings-object>environment settings object</a> or null, only to be used as a <a href=https://fetch.spec.whatwg.org/#concept-request-client id=navigation-supporting-concepts:concept-request-client data-x-internal=concept-request-client>request client</a><dt><dfn id=source-snapshot-params-policy-container>source policy container</dfn><dd>a <a id=navigation-supporting-concepts:policy-container href=browsers.html#policy-container>policy container</a></dl>

  <p>To <dfn id=snapshotting-source-snapshot-params>snapshot source snapshot params</dfn>
  given a <code id=navigation-supporting-concepts:document-2><a href=dom.html#document>Document</a></code>-or-null <var>sourceDocument</var>:</p>

  <ol><li>
    <p>If <var>sourceDocument</var> is null, then return a new <a href=#source-snapshot-params id=navigation-supporting-concepts:source-snapshot-params>source snapshot params</a>
    with</p>

    <dl class=props><dt><a href=#source-snapshot-params-activation id=navigation-supporting-concepts:source-snapshot-params-activation>has transient activation</a><dd>true<dt><a href=#source-snapshot-params-sandbox id=navigation-supporting-concepts:source-snapshot-params-sandbox>sandboxing flags</a><dd>an empty <a id=navigation-supporting-concepts:sandboxing-flag-set-2 href=browsers.html#sandboxing-flag-set>sandboxing flag set</a><dt><a href=#source-snapshot-params-download id=navigation-supporting-concepts:source-snapshot-params-download>allows downloading</a><dd>true<dt><a href=#source-snapshot-params-client id=navigation-supporting-concepts:source-snapshot-params-client>fetch client</a><dd>null<dt><a href=#source-snapshot-params-policy-container id=navigation-supporting-concepts:source-snapshot-params-policy-container>source policy container</a><dd>a new <a id=navigation-supporting-concepts:policy-container-2 href=browsers.html#policy-container>policy container</a></dl>

    <p class=note>This <a href=#assert-null-sourcedocument>only occurs</a> in the case of a
    browser UI-initiated navigation.</p>
   <li>
    <p>Return a new <a href=#source-snapshot-params id=navigation-supporting-concepts:source-snapshot-params-2>source snapshot params</a> with

    <dl class=props><dt><a href=#source-snapshot-params-activation id=navigation-supporting-concepts:source-snapshot-params-activation-2>has transient activation</a><dd>true if <var>sourceDocument</var>'s <a id=navigation-supporting-concepts:concept-relevant-global href=webappapis.html#concept-relevant-global>relevant global object</a> has <a id=navigation-supporting-concepts:transient-activation href=interaction.html#transient-activation>transient
     activation</a>; otherwise false<dt><a href=#source-snapshot-params-sandbox id=navigation-supporting-concepts:source-snapshot-params-sandbox-2>sandboxing flags</a><dd><var>sourceDocument</var>'s <a id=navigation-supporting-concepts:active-sandboxing-flag-set href=browsers.html#active-sandboxing-flag-set>active sandboxing flag set</a><dt><a href=#source-snapshot-params-download id=navigation-supporting-concepts:source-snapshot-params-download-2>allows downloading</a><dd>false if <var>sourceDocument</var>'s <a id=navigation-supporting-concepts:active-sandboxing-flag-set-2 href=browsers.html#active-sandboxing-flag-set>active sandboxing flag set</a> has the
     <a id=navigation-supporting-concepts:sandboxed-downloads-browsing-context-flag href=browsers.html#sandboxed-downloads-browsing-context-flag>sandboxed downloads browsing context flag</a> set; otherwise true<dt><a href=#source-snapshot-params-client id=navigation-supporting-concepts:source-snapshot-params-client-2>fetch client</a><dd><var>sourceDocument</var>'s <a id=navigation-supporting-concepts:relevant-settings-object href=webappapis.html#relevant-settings-object>relevant settings object</a><dt><a href=#source-snapshot-params-policy-container id=navigation-supporting-concepts:source-snapshot-params-policy-container-2>source policy container</a><dd>a <a href=browsers.html#clone-a-policy-container id=navigation-supporting-concepts:clone-a-policy-container>clone</a> of <var>sourceDocument</var>'s <a href=dom.html#concept-document-policy-container id=navigation-supporting-concepts:concept-document-policy-container>policy container</a></dl>
   </ol>

  <hr>

  <p>The <dfn id=target-snapshot-params>target snapshot params</dfn> <a id=navigation-supporting-concepts:struct-2 href=https://infra.spec.whatwg.org/#struct data-x-internal=struct>struct</a> is used to capture data from a
  <a id=navigation-supporting-concepts:navigable href=document-sequences.html#navigable>navigable</a> being navigated. Like <a href=#source-snapshot-params id=navigation-supporting-concepts:source-snapshot-params-3>source snapshot params</a>, it is
  snapshotted at the beginning of a navigation and used throughout the navigation's lifetime. It
  has the following <a href=https://infra.spec.whatwg.org/#struct-item id=navigation-supporting-concepts:struct-item-2 data-x-internal=struct-item>items</a>:</p>

  <dl><dt><dfn id=target-snapshot-params-sandbox>sandboxing flags</dfn><dd>a <a id=navigation-supporting-concepts:sandboxing-flag-set-3 href=browsers.html#sandboxing-flag-set>sandboxing flag set</a></dl>

  <p>To <dfn id=snapshotting-target-snapshot-params>snapshot target snapshot params</dfn>
  given a <a id=navigation-supporting-concepts:navigable-2 href=document-sequences.html#navigable>navigable</a> <var>targetNavigable</var>, return a new <a href=#target-snapshot-params id=navigation-supporting-concepts:target-snapshot-params>target snapshot
  params</a> with <a href=#target-snapshot-params-sandbox id=navigation-supporting-concepts:target-snapshot-params-sandbox>sandboxing flags</a> set to
  the result of <a id=navigation-supporting-concepts:determining-the-creation-sandboxing-flags href=browsers.html#determining-the-creation-sandboxing-flags>determining the creation sandboxing flags</a> given
  <var>targetNavigable</var>'s <a href=document-sequences.html#nav-bc id=navigation-supporting-concepts:nav-bc>active browsing context</a> and
  <var>targetNavigable</var>'s <a href=document-sequences.html#nav-container id=navigation-supporting-concepts:nav-container>container</a>.</p>

  <hr>

  <p>Much of the navigation process is concerned with determining how to create a new
  <code id=navigation-supporting-concepts:document-3><a href=dom.html#document>Document</a></code>, which ultimately happens in the <a href=document-lifecycle.html#initialise-the-document-object id=navigation-supporting-concepts:initialise-the-document-object>create and initialize a <code>Document</code> object</a>
  algorithm. The parameters to that algorithm are tracked via a <dfn id=navigation-params>navigation params</dfn>
  <a id=navigation-supporting-concepts:struct-3 href=https://infra.spec.whatwg.org/#struct data-x-internal=struct>struct</a>, which has the following <a href=https://infra.spec.whatwg.org/#struct-item id=navigation-supporting-concepts:struct-item-3 data-x-internal=struct-item>items</a>:</p>

  
  <dl><dt><dfn id=navigation-params-id>id</dfn><dd>null or a <a href=#navigation-id id=navigation-supporting-concepts:navigation-id>navigation ID</a><dt><dfn id=navigation-params-navigable>navigable</dfn><dd>the <a id=navigation-supporting-concepts:navigable-3 href=document-sequences.html#navigable>navigable</a> to be navigated<dt><dfn id=navigation-params-request>request</dfn><dd>null or a <a href=https://fetch.spec.whatwg.org/#concept-request id=navigation-supporting-concepts:concept-request data-x-internal=concept-request>request</a> that started the navigation<dt><dfn id=navigation-params-response>response</dfn><dd>a <a href=https://fetch.spec.whatwg.org/#concept-response id=navigation-supporting-concepts:concept-response data-x-internal=concept-response>response</a> that ultimately was navigated to
   (potentially a <a id=navigation-supporting-concepts:network-error href=https://fetch.spec.whatwg.org/#concept-network-error data-x-internal=network-error>network error</a>)<dt><dfn id=navigation-params-fetch-controller>fetch controller</dfn><dd>null or a <a id=navigation-supporting-concepts:fetch-controller href=https://fetch.spec.whatwg.org/#fetch-controller data-x-internal=fetch-controller>fetch controller</a><dt><dfn id=navigation-params-commit-early-hints>commit early hints</dfn><dd>null or an algorithm accepting a <code id=navigation-supporting-concepts:document-4><a href=dom.html#document>Document</a></code>, once it has been created<dt><dfn id=navigation-params-coop-enforcement-result>COOP enforcement result</dfn><dd>an <a href=browsers.html#coop-enforcement-result id=navigation-supporting-concepts:coop-enforcement-result>opener policy enforcement result</a>, used for
   reporting and potentially for causing a <a href=browsers.html#browsing-context-group-switches-due-to-cross-origin-opener-policy>browsing context
   group switch</a><dt><dfn id=navigation-params-reserved-environment>reserved environment</dfn><dd>null or an <a id=navigation-supporting-concepts:environment href=webappapis.html#environment>environment</a> reserved for the new <code id=navigation-supporting-concepts:document-5><a href=dom.html#document>Document</a></code><dt><dfn id=navigation-params-origin>origin</dfn><dd>an <a id=navigation-supporting-concepts:concept-origin href=browsers.html#concept-origin>origin</a> to use for the new <code id=navigation-supporting-concepts:document-6><a href=dom.html#document>Document</a></code><dt><dfn id=navigation-params-policy-container>policy container</dfn><dd>a <a id=navigation-supporting-concepts:policy-container-3 href=browsers.html#policy-container>policy container</a> to use for the new <code id=navigation-supporting-concepts:document-7><a href=dom.html#document>Document</a></code><dt><dfn id=navigation-params-sandboxing>final sandboxing flag set</dfn><dd>a <a id=navigation-supporting-concepts:sandboxing-flag-set-4 href=browsers.html#sandboxing-flag-set>sandboxing flag set</a> to impose on the new <code id=navigation-supporting-concepts:document-8><a href=dom.html#document>Document</a></code><dt><dfn id=navigation-params-coop>opener policy</dfn><dd>an <a id=navigation-supporting-concepts:cross-origin-opener-policy href=browsers.html#cross-origin-opener-policy>opener policy</a> to use for the new <code id=navigation-supporting-concepts:document-9><a href=dom.html#document>Document</a></code><dt><dfn id=navigation-params-nav-timing-type>navigation timing type</dfn><dd>a <code id=navigation-supporting-concepts:navigationtimingtype><a data-x-internal=navigationtimingtype href=https://w3c.github.io/navigation-timing/#dom-navigationtimingtype>NavigationTimingType</a></code> used for <a href=https://w3c.github.io/navigation-timing/#dfn-create-the-navigation-timing-entry id=navigation-supporting-concepts:create-the-navigation-timing-entry data-x-internal=create-the-navigation-timing-entry>creating the navigation timing entry</a> for the new <code id=navigation-supporting-concepts:document-10><a href=dom.html#document>Document</a></code><dt><dfn id=navigation-params-about-base-url>about base URL</dfn><dd>a <a id=navigation-supporting-concepts:url href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> or null used to populate the new <code id=navigation-supporting-concepts:document-11><a href=dom.html#document>Document</a></code>'s <a href=dom.html#concept-document-about-base-url id=navigation-supporting-concepts:concept-document-about-base-url>about base URL</a><dt><dfn id=navigation-params-user-involvement>user involvement</dfn><dd>a <a href=#user-navigation-involvement id=navigation-supporting-concepts:user-navigation-involvement>user navigation involvement</a> used when <a href=browsers.html#obtain-browsing-context-navigation id=navigation-supporting-concepts:obtain-browsing-context-navigation>obtaining a browsing context</a> for the new
   <code id=navigation-supporting-concepts:document-12><a href=dom.html#document>Document</a></code></dl>

  <p class=note>Once a <a href=#navigation-params id=navigation-supporting-concepts:navigation-params>navigation params</a> struct is created, this standard does not
  mutate any of its <a href=https://infra.spec.whatwg.org/#struct-item id=navigation-supporting-concepts:struct-item-4 data-x-internal=struct-item>items</a>. They are only passed onward to other
  algorithms.</p>

  <hr>

  <p>A <dfn id=navigation-id>navigation ID</dfn> is a UUID string generated during navigation. It is used to
  interface with the <cite>WebDriver BiDi</cite> specification as well as to track the <a href=#ongoing-navigation id=navigation-supporting-concepts:ongoing-navigation>ongoing
  navigation</a>. <a href=references.html#refsWEBDRIVERBIDI>[WEBDRIVERBIDI]</a></p>

  <hr>

  <p>After <code id=navigation-supporting-concepts:document-13><a href=dom.html#document>Document</a></code> creation, the relevant <a id=navigation-supporting-concepts:traversable-navigable href=document-sequences.html#traversable-navigable>traversable navigable</a>'s <a href=document-sequences.html#tn-session-history-entries id=navigation-supporting-concepts:tn-session-history-entries>session history</a> gets updated. The
  <code id=navigation-supporting-concepts:navigationhistorybehavior><a href=nav-history-apis.html#navigationhistorybehavior>NavigationHistoryBehavior</a></code> enumeration is used to indicate the desired type of session
  history update to the <a href=#navigate id=navigation-supporting-concepts:navigate-2>navigate</a> algorithm. It is one of the following:</p>

  <dl><dt id=hh-default><span id=hh-push></span>"<dfn data-dfn-for=NavigationHistoryBehavior id=navigationhistorybehavior-push data-dfn-type=enum-value><code>push</code></dfn>"<dd>A regular navigation which adds a new <a href=#session-history-entry id=navigation-supporting-concepts:session-history-entry>session history entry</a>, and will
   <a href=#clear-the-forward-session-history id=navigation-supporting-concepts:clear-the-forward-session-history>clear the forward session history</a>.<dt id=hh-replace>"<dfn data-dfn-for=NavigationHistoryBehavior id=navigationhistorybehavior-replace data-dfn-type=enum-value><code>replace</code></dfn>"<dd>A navigation that will replace the <a href=document-sequences.html#nav-active-history-entry id=navigation-supporting-concepts:nav-active-history-entry>active session
   history entry</a>.<dt>"<dfn data-dfn-for=NavigationHistoryBehavior id=navigationhistorybehavior-auto data-dfn-type=enum-value><code>auto</code></dfn>"<dd>The default value, which will be converted very early in the <a href=#navigate id=navigation-supporting-concepts:navigate-3>navigate</a> algorithm
   into "<code id=navigation-supporting-concepts:navigationhistorybehavior-push><a href=#navigationhistorybehavior-push>push</a></code>" or "<code id=navigation-supporting-concepts:navigationhistorybehavior-replace><a href=#navigationhistorybehavior-replace>replace</a></code>". Usually it becomes "<code id=navigation-supporting-concepts:navigationhistorybehavior-push-2><a href=#navigationhistorybehavior-push>push</a></code>", but under <a href=#navigate-convert-to-replace>certain circumstances</a> it becomes "<code id=navigation-supporting-concepts:navigationhistorybehavior-replace-2><a href=#navigationhistorybehavior-replace>replace</a></code>" instead.</dl>

  <p>A <dfn id=history-handling-behavior>history handling behavior</dfn> is a <code id=navigation-supporting-concepts:navigationhistorybehavior-2><a href=nav-history-apis.html#navigationhistorybehavior>NavigationHistoryBehavior</a></code> that is
  either "<code id=navigation-supporting-concepts:navigationhistorybehavior-push-3><a href=#navigationhistorybehavior-push>push</a></code>" or "<code id=navigation-supporting-concepts:navigationhistorybehavior-replace-3><a href=#navigationhistorybehavior-replace>replace</a></code>", i.e., that has been resolved away from
  any initial "<code id=navigation-supporting-concepts:navigationhistorybehavior-auto><a href=#navigationhistorybehavior-auto>auto</a></code>" value.</p>

  <p><dfn id=the-navigation-must-be-a-replace>The navigation must be a replace</dfn>, given a <a id=navigation-supporting-concepts:url-2 href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> <var>url</var> and a
  <code id=navigation-supporting-concepts:document-14><a href=dom.html#document>Document</a></code> <var>document</var>, if any of the following are true:</p>

  <ul><li><p><var>url</var>'s <a href=https://url.spec.whatwg.org/#concept-url-scheme id=navigation-supporting-concepts:concept-url-scheme data-x-internal=concept-url-scheme>scheme</a> is "<code id=navigation-supporting-concepts:the-javascript:-url-special-case><a href=#the-javascript:-url-special-case>javascript</a></code>"; or<li><p><var>document</var>'s <a id=navigation-supporting-concepts:is-initial-about:blank href=dom.html#is-initial-about:blank>is initial <code>about:blank</code></a> is true.</ul>

  <div class=note>
   <p>Other cases that often, but not always, force a "<code id=navigation-supporting-concepts:navigationhistorybehavior-replace-4><a href=#navigationhistorybehavior-replace>replace</a></code>" navigation are:</p>

   <ul><li><p>if the <code id=navigation-supporting-concepts:document-15><a href=dom.html#document>Document</a></code> is not <a id=navigation-supporting-concepts:completely-loaded href=document-lifecycle.html#completely-loaded>completely loaded</a>; or<li><p>if the target <a id=navigation-supporting-concepts:url-3 href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> equals the <code id=navigation-supporting-concepts:document-16><a href=dom.html#document>Document</a></code>'s <a href=https://dom.spec.whatwg.org/#concept-document-url id="navigation-supporting-concepts:the-document's-address" data-x-internal="the-document's-address">URL</a>.</ul>
  </div>

  <hr>

  <p>Various parts of the platform track whether a user is involved in a navigation. A <dfn id=user-navigation-involvement data-export="">user navigation involvement</dfn> is one of the following:</p>

  <dl><dt>"<dfn data-dfn-for="user navigation involvement" id=uni-browser-ui data-export=""><code>browser UI</code></dfn>"<dd>The navigation was initiated by the user via browser UI mechanisms.<dt>"<dfn data-dfn-for="user navigation involvement" id=uni-activation data-export=""><code>activation</code></dfn>"<dd>The navigation was initiated by the user via the <a id=navigation-supporting-concepts:activation-behaviour href=https://dom.spec.whatwg.org/#eventtarget-activation-behavior data-x-internal=activation-behaviour>activation behavior</a> of an
   element.<dt>"<dfn data-dfn-for="user navigation involvement" id=uni-none data-export=""><code>none</code></dfn>"<dd>The navigation was not initiated by the user.</dl>

  <p>For convenience at certain call sites, the <dfn data-dfn-for=Event id=event-uni>user navigation
  involvement</dfn> for an <code id=navigation-supporting-concepts:event><a data-x-internal=event href=https://dom.spec.whatwg.org/#interface-event>Event</a></code> <var>event</var> is defined as follows:</p>

  <ol><li><p><a id=navigation-supporting-concepts:assert href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: this algorithm is being called as part of an <a id=navigation-supporting-concepts:activation-behaviour-2 href=https://dom.spec.whatwg.org/#eventtarget-activation-behavior data-x-internal=activation-behaviour>activation
   behavior</a> definition.<li><p><a id=navigation-supporting-concepts:assert-2 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>event</var>'s <code id=navigation-supporting-concepts:dom-event-type><a data-x-internal=dom-event-type href=https://dom.spec.whatwg.org/#dom-event-type>type</a></code> is
   "<code id=navigation-supporting-concepts:event-click><a data-x-internal=event-click href=https://w3c.github.io/uievents/#event-type-click>click</a></code>".<li><p>If <var>event</var>'s <code id=navigation-supporting-concepts:dom-event-istrusted><a data-x-internal=dom-event-istrusted href=https://dom.spec.whatwg.org/#dom-event-istrusted>isTrusted</a></code> is initialized
   to true, then return "<code id=navigation-supporting-concepts:uni-activation><a href=#uni-activation>activation</a></code>".<li><p>Return "<code id=navigation-supporting-concepts:uni-none><a href=#uni-none>none</a></code>".</ol>


  <h5 id=beginning-navigation><span class=secno>7.4.2.2</span> Beginning navigation<a href=#beginning-navigation class=self-link></a></h5>

  
  

  <p>To <dfn id=navigate data-export="">navigate</dfn> a <a id=beginning-navigation:navigable href=document-sequences.html#navigable>navigable</a> <var>navigable</var> to a
  <a id=beginning-navigation:url href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> <var>url</var> using an optional <code id=beginning-navigation:document><a href=dom.html#document>Document</a></code>-or-null <var id=source-browsing-context>sourceDocument</var> (default null), with an optional <a href=#post-resource id=beginning-navigation:post-resource>POST
  resource</a>, string, or null <dfn data-dfn-for=navigate id=navigation-resource data-export=""><var>documentResource</var></dfn> (default null), an optional <a href=https://fetch.spec.whatwg.org/#concept-response id=beginning-navigation:concept-response data-x-internal=concept-response>response</a>-or-null <dfn data-dfn-for=navigate id=navigation-response data-export=""><var>response</var></dfn> (default null), an optional boolean <dfn data-dfn-for=navigate id=exceptions-enabled data-export=""><var>exceptionsEnabled</var></dfn> (default false), an optional
  <code id=beginning-navigation:navigationhistorybehavior><a href=nav-history-apis.html#navigationhistorybehavior>NavigationHistoryBehavior</a></code> <dfn data-dfn-for=navigate id=navigation-hh data-export=""><var>historyHandling</var></dfn> (default "<code id=beginning-navigation:navigationhistorybehavior-auto><a href=#navigationhistorybehavior-auto>auto</a></code>"), an optional <a href=#serialized-state id=beginning-navigation:serialized-state>serialized
  state</a>-or-null <dfn data-dfn-for=navigate id=navigation-navigation-api-state data-export=""><var>navigationAPIState</var></dfn> (default null), an optional <a id=beginning-navigation:entry-list href=form-control-infrastructure.html#entry-list>entry list</a> or
  null <dfn data-dfn-for=navigate id=navigation-form-data-entry-list data-export=""><var>formDataEntryList</var></dfn> (default null), an optional <a id=beginning-navigation:referrer-policy href=https://w3c.github.io/webappsec-referrer-policy/#referrer-policy data-x-internal=referrer-policy>referrer policy</a>
  <dfn id=navigation-referrer-policy><var>referrerPolicy</var></dfn> (default the empty
  string), an optional <a href=#user-navigation-involvement id=beginning-navigation:user-navigation-involvement>user navigation involvement</a> <dfn id=navigation-user-involvement><var>userInvolvement</var></dfn> (default "<code id=beginning-navigation:uni-none><a href=#uni-none>none</a></code>"), an optional <code id=beginning-navigation:element><a data-x-internal=element href=https://dom.spec.whatwg.org/#interface-element>Element</a></code> <dfn id=navigation-source-element><var>sourceElement</var></dfn> (default null), and an
  optional boolean <dfn data-dfn-for=navigate id=navigation-initial-insertion><var>initialInsertion</var></dfn> (default
  false):</p>

  <ol><li><p>Let <var>cspNavigationType</var> be "<code>form-submission</code>" if
   <var>formDataEntryList</var> is non-null; otherwise "<code>other</code>".<li><p>Let <var>sourceSnapshotParams</var> be the result of <a href=#snapshotting-source-snapshot-params id=beginning-navigation:snapshotting-source-snapshot-params>snapshotting source snapshot
   params</a> given <var>sourceDocument</var>.<li><p>Let <var>initiatorOriginSnapshot</var> be a new <a href=browsers.html#concept-origin-opaque id=beginning-navigation:concept-origin-opaque>opaque origin</a>.<li><p>Let <var>initiatorBaseURLSnapshot</var> be <code id=beginning-navigation:about:blank><a href=infrastructure.html#about:blank>about:blank</a></code>.<li>
    <p>If <var>sourceDocument</var> is null:</p>

    <ol><li id=assert-null-sourcedocument><p><a id=beginning-navigation:assert href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>userInvolvement</var> is
     "<code id=beginning-navigation:uni-browser-ui><a href=#uni-browser-ui>browser UI</a></code>".<li><p>If <var>url</var>'s <a href=https://url.spec.whatwg.org/#concept-url-scheme id=beginning-navigation:concept-url-scheme data-x-internal=concept-url-scheme>scheme</a> is "<code id=beginning-navigation:the-javascript:-url-special-case><a href=#the-javascript:-url-special-case>javascript</a></code>", then set <var>initiatorOriginSnapshot</var> to
     <var>navigable</var>'s <a href=document-sequences.html#nav-document id=beginning-navigation:nav-document>active document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=beginning-navigation:concept-document-origin data-x-internal=concept-document-origin>origin</a>.</ol>
   <li>
    <p>Otherwise:</p>

    <ol><li><p><a id=beginning-navigation:assert-2 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>userInvolvement</var> is not "<code id=beginning-navigation:uni-browser-ui-2><a href=#uni-browser-ui>browser UI</a></code>".<li id=sandboxLinks>
      <p>If <var>sourceDocument</var>'s <a id=beginning-navigation:node-navigable href=document-sequences.html#node-navigable>node navigable</a> is not <a href=#allowed-to-navigate id=beginning-navigation:allowed-to-navigate>allowed by
      sandboxing to navigate</a> <var>navigable</var> given <var>sourceSnapshotParams</var>:</p>

      <ol><li><p>If <var>exceptionsEnabled</var> is true, then throw a
       <a id=beginning-navigation:securityerror href=https://webidl.spec.whatwg.org/#securityerror data-x-internal=securityerror>"<code>SecurityError</code>"</a> <code id=beginning-navigation:domexception><a data-x-internal=domexception href=https://webidl.spec.whatwg.org/#dfn-DOMException>DOMException</a></code>.<li><p>Return.</ol>
     <li><p>Set <var>initiatorOriginSnapshot</var> to <var>sourceDocument</var>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=beginning-navigation:concept-document-origin-2 data-x-internal=concept-document-origin>origin</a>.<li><p>Set <var>initiatorBaseURLSnapshot</var> to <var>sourceDocument</var>'s <a id=beginning-navigation:document-base-url href=urls-and-fetching.html#document-base-url>document
     base URL</a>.</ol>
   <li><p>Let <var>navigationId</var> be the result of <a id=beginning-navigation:generating-a-random-uuid href=https://w3c.github.io/webcrypto/#dfn-generate-a-random-uuid data-x-internal=generating-a-random-uuid>generating a random UUID</a>.
   <a href=references.html#refsWEBCRYPTO>[WEBCRYPTO]</a><li>
    <p>If the <a id=beginning-navigation:surrounding-agent href=https://tc39.es/ecma262/#surrounding-agent data-x-internal=surrounding-agent>surrounding agent</a> is equal to <var>navigable</var>'s <a href=document-sequences.html#nav-document id=beginning-navigation:nav-document-2>active document</a>'s <a id=beginning-navigation:relevant-agent href=webappapis.html#relevant-agent>relevant agent</a>, then continue these
    steps. Otherwise, <a id=beginning-navigation:queue-a-global-task href=webappapis.html#queue-a-global-task>queue a global task</a> on the <a id=beginning-navigation:navigation-and-traversal-task-source href=webappapis.html#navigation-and-traversal-task-source>navigation and traversal task
    source</a> given <var>navigable</var>'s <a href=document-sequences.html#nav-window id=beginning-navigation:nav-window>active window</a> to
    continue these steps.</p>

    <div class=note>
     <p>We do this because we are about to look at a lot of properties of <var>navigable</var>'s
     <a href=document-sequences.html#nav-document id=beginning-navigation:nav-document-3>active document</a>, which are in theory only accessible over
     in the appropriate <a id=beginning-navigation:event-loop href=webappapis.html#event-loop>event loop</a>. (But, we do not want to unconditionally queue a
     task, since — for example — same-event-loop <a href=#navigate-fragid id=beginning-navigation:navigate-fragid>fragment navigations</a> need to take effect synchronously.)</p>

     <p>Another implementation strategy would be to replicate the relevant information across event
     loops, or into a canonical "browser process", so that it can be consulted without queueing a
     task. This could give different results than what we specify here in edge cases, where the
     relevant properties have changed over in the target event loop but not yet been replicated.
     Further testing is needed to determine which of these strategies best matches browser
     behavior, in such racy edge cases.</p>
    </div>
   <li><p>If <var>navigable</var>'s <a href=document-sequences.html#nav-document id=beginning-navigation:nav-document-4>active document</a>'s
   <a id=beginning-navigation:unload-counter href=document-lifecycle.html#unload-counter>unload counter</a> is greater than 0, then invoke <a id=beginning-navigation:webdriver-bidi-navigation-failed href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-navigation-failed data-x-internal=webdriver-bidi-navigation-failed>WebDriver BiDi navigation
   failed</a> with <var>navigable</var> and a <a id=beginning-navigation:webdriver-bidi-navigation-status href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-navigation-status data-x-internal=webdriver-bidi-navigation-status>WebDriver BiDi navigation status</a> whose
   <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-id id=beginning-navigation:navigation-status-id data-x-internal=navigation-status-id>id</a> is <var>navigationId</var>, <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-status id=beginning-navigation:navigation-status-status data-x-internal=navigation-status-status>status</a> is "<code id=beginning-navigation:navigation-status-canceled><a data-x-internal=navigation-status-canceled href=https://w3c.github.io/webdriver-bidi/#navigation-status-canceled>canceled</a></code>", and <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-url id=beginning-navigation:navigation-status-url data-x-internal=navigation-status-url>url</a> is <var>url</var>, and return.<li><p>Let <var>container</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-container id=beginning-navigation:nav-container>container</a>.<li><p>If <var>container</var> is an <code id=beginning-navigation:the-iframe-element><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code> element and <a id=beginning-navigation:will-lazy-load-element-steps href=urls-and-fetching.html#will-lazy-load-element-steps>will lazy load
   element steps</a> given <var>container</var> returns true, then <a id=beginning-navigation:stop-intersection-observing-a-lazy-loading-element href=urls-and-fetching.html#stop-intersection-observing-a-lazy-loading-element>stop
   intersection-observing a lazy loading element</a> <var>container</var> and set
   <var>container</var>'s <a id=beginning-navigation:lazy-load-resumption-steps href=urls-and-fetching.html#lazy-load-resumption-steps>lazy load resumption steps</a> to null.<li id=navigate-convert-to-replace>
    <p>If <var>historyHandling</var> is "<code id=beginning-navigation:navigationhistorybehavior-auto-2><a href=#navigationhistorybehavior-auto>auto</a></code>",
    then:</p>

    <ol><li><p>If <var>url</var> <a href=https://url.spec.whatwg.org/#concept-url-equals id=beginning-navigation:concept-url-equals data-x-internal=concept-url-equals>equals</a>
     <var>navigable</var>'s <a href=document-sequences.html#nav-document id=beginning-navigation:nav-document-5>active document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-url id="beginning-navigation:the-document's-address" data-x-internal="the-document's-address">URL</a>, and <var>initiatorOriginSnapshot</var> is <a id=beginning-navigation:same-origin href=browsers.html#same-origin>same
     origin</a> with <var>targetNavigable</var>'s <a href=document-sequences.html#nav-document id=beginning-navigation:nav-document-6>active
     document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=beginning-navigation:concept-document-origin-3 data-x-internal=concept-document-origin>origin</a>, then set
     <var>historyHandling</var> to "<code id=beginning-navigation:navigationhistorybehavior-replace><a href=#navigationhistorybehavior-replace>replace</a></code>".<li><p>Otherwise, set <var>historyHandling</var> to "<code id=beginning-navigation:navigationhistorybehavior-push><a href=#navigationhistorybehavior-push>push</a></code>".</ol>
   <li><p>If <a href=#the-navigation-must-be-a-replace id=beginning-navigation:the-navigation-must-be-a-replace>the navigation must be a replace</a> given <var>url</var> and
   <var>navigable</var>'s <a href=document-sequences.html#nav-document id=beginning-navigation:nav-document-7>active document</a>, then set
   <var>historyHandling</var> to "<code id=beginning-navigation:navigationhistorybehavior-replace-2><a href=#navigationhistorybehavior-replace>replace</a></code>".<li id=navigate-fragid-step>
    <p>If all of the following are true:</p>

    <ul><li><p><var>documentResource</var> is null;<li><p><var>response</var> is null;<li><p><var>url</var> <a href=https://url.spec.whatwg.org/#concept-url-equals id=beginning-navigation:concept-url-equals-2 data-x-internal=concept-url-equals>equals</a> <var>navigable</var>'s
     <a href=document-sequences.html#nav-active-history-entry id=beginning-navigation:nav-active-history-entry>active session history entry</a>'s <a href=#she-url id=beginning-navigation:she-url>URL</a> with <a href=https://url.spec.whatwg.org/#url-equals-exclude-fragments id=beginning-navigation:url-equals-exclude-fragments data-x-internal=url-equals-exclude-fragments><i>exclude
     fragments</i></a> set to true; and<li><p><var>url</var>'s <a href=https://url.spec.whatwg.org/#concept-url-fragment id=beginning-navigation:concept-url-fragment data-x-internal=concept-url-fragment>fragment</a> is
     non-null,</ul>

    <p>then:</p>

    <ol><li><p><a href=#navigate-fragid id=beginning-navigation:navigate-fragid-2>Navigate to a fragment</a> given <var>navigable</var>,
     <var>url</var>, <var>historyHandling</var>, <var>userInvolvement</var>,
     <var>sourceElement</var>, <var>navigationAPIState</var>, and <var>navigationId</var>.<li><p>Return.</ol>
   <li><p>If <var>navigable</var>'s <a href=document-sequences.html#nav-parent id=beginning-navigation:nav-parent>parent</a> is non-null, then set
   <var>navigable</var>'s <a id=beginning-navigation:delaying-load-events-mode href=document-sequences.html#delaying-load-events-mode>is delaying <code>load</code> events</a> to
   true.<li><p>Let <var>targetSnapshotParams</var> be the result of <a href=#snapshotting-target-snapshot-params id=beginning-navigation:snapshotting-target-snapshot-params>snapshotting target snapshot
   params</a> given <var>navigable</var>.<li><p>Invoke <a id=beginning-navigation:webdriver-bidi-navigation-started href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-navigation-started data-x-internal=webdriver-bidi-navigation-started>WebDriver BiDi navigation started</a> with <var>navigable</var> and a new
   <a id=beginning-navigation:webdriver-bidi-navigation-status-2 href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-navigation-status data-x-internal=webdriver-bidi-navigation-status>WebDriver BiDi navigation status</a> whose <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-id id=beginning-navigation:navigation-status-id-2 data-x-internal=navigation-status-id>id</a>
   is <var>navigationId</var>, <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-status id=beginning-navigation:navigation-status-status-2 data-x-internal=navigation-status-status>status</a> is "<code id=beginning-navigation:navigation-status-pending><a data-x-internal=navigation-status-pending href=https://w3c.github.io/webdriver-bidi/#navigation-status-pending>pending</a></code>", and <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-url id=beginning-navigation:navigation-status-url-2 data-x-internal=navigation-status-url>url</a> is <var>url</var>.<li>
    <p>If <var>navigable</var>'s <a href=#ongoing-navigation id=beginning-navigation:ongoing-navigation>ongoing navigation</a> is "<code>traversal</code>", then:</p>

    <ol><li><p>Invoke <a id=beginning-navigation:webdriver-bidi-navigation-failed-2 href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-navigation-failed data-x-internal=webdriver-bidi-navigation-failed>WebDriver BiDi navigation failed</a> with <var>navigable</var> and a new
     <a id=beginning-navigation:webdriver-bidi-navigation-status-3 href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-navigation-status data-x-internal=webdriver-bidi-navigation-status>WebDriver BiDi navigation status</a> whose <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-id id=beginning-navigation:navigation-status-id-3 data-x-internal=navigation-status-id>id</a> is <var>navigationId</var>, <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-status id=beginning-navigation:navigation-status-status-3 data-x-internal=navigation-status-status>status</a> is "<code id=beginning-navigation:navigation-status-canceled-2><a data-x-internal=navigation-status-canceled href=https://w3c.github.io/webdriver-bidi/#navigation-status-canceled>canceled</a></code>", and <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-url id=beginning-navigation:navigation-status-url-3 data-x-internal=navigation-status-url>url</a> is <var>url</var>.<li><p>Return.</ol>

    <p class=note>Any attempts to navigate a <a id=beginning-navigation:navigable-2 href=document-sequences.html#navigable>navigable</a> that is currently <a href=#apply-the-traverse-history-step id=beginning-navigation:apply-the-traverse-history-step>traversing</a> are ignored.</p>
   <li>
    <p><a href=#set-the-ongoing-navigation id=beginning-navigation:set-the-ongoing-navigation>Set the ongoing navigation</a> for <var>navigable</var> to
    <var>navigationId</var>.</p>

    <p class=note>This will have the effect of aborting other ongoing navigations of
    <var>navigable</var>, since at certain points during navigation changes to the <a href=#ongoing-navigation id=beginning-navigation:ongoing-navigation-2>ongoing
    navigation</a> will cause further work to be abandoned.</p>
   <li>
    <p>If <var>url</var>'s <a href=https://url.spec.whatwg.org/#concept-url-scheme id=beginning-navigation:concept-url-scheme-2 data-x-internal=concept-url-scheme>scheme</a> is "<code id=beginning-navigation:the-javascript:-url-special-case-2><a href=#the-javascript:-url-special-case>javascript</a></code>", then:</p>

    <ol><li><p><a id=beginning-navigation:queue-a-global-task-2 href=webappapis.html#queue-a-global-task>Queue a global task</a> on the <a id=beginning-navigation:navigation-and-traversal-task-source-2 href=webappapis.html#navigation-and-traversal-task-source>navigation and traversal task
     source</a> given <var>navigable</var>'s <a href=document-sequences.html#nav-window id=beginning-navigation:nav-window-2>active window</a> to
     <a href=#navigate-to-a-javascript:-url id=beginning-navigation:navigate-to-a-javascript:-url>navigate to a <code>javascript:</code> URL</a> given <var>navigable</var>,
     <var>url</var>, <var>historyHandling</var>, <var>sourceSnapshotParams</var>,
     <var>initiatorOriginSnapshot</var>, <var>userInvolvement</var>,
     <var>cspNavigationType</var>, and <var>initialInsertion</var>.<li><p>Return.</ol>
   <li>
    <p>If all of the following are true:</p>

    <ul><li><p><var>userInvolvement</var> is not "<code id=beginning-navigation:uni-browser-ui-3><a href=#uni-browser-ui>browser
     UI</a></code>";<li><p><var>navigable</var>'s <a href=document-sequences.html#nav-document id=beginning-navigation:nav-document-8>active document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=beginning-navigation:concept-document-origin-4 data-x-internal=concept-document-origin>origin</a> is <a id=beginning-navigation:same-origin-domain href=browsers.html#same-origin-domain>same origin-domain</a> with
     <var>sourceDocument</var>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=beginning-navigation:concept-document-origin-5 data-x-internal=concept-document-origin>origin</a>;<li><p><var>navigable</var>'s <a href=document-sequences.html#nav-document id=beginning-navigation:nav-document-9>active document</a>'s <a id=beginning-navigation:is-initial-about:blank href=dom.html#is-initial-about:blank>is
     initial <code>about:blank</code></a> is false; and<li><p><var>url</var>'s <a href=https://url.spec.whatwg.org/#concept-url-scheme id=beginning-navigation:concept-url-scheme-3 data-x-internal=concept-url-scheme>scheme</a> is a <a id=beginning-navigation:fetch-scheme href=https://fetch.spec.whatwg.org/#fetch-scheme data-x-internal=fetch-scheme>fetch
     scheme</a>,</ul>

    <p>then:</p>

    <ol><li><p>Let <var>navigation</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-window id=beginning-navigation:nav-window-3>active
     window</a>'s <a href=nav-history-apis.html#window-navigation-api id=beginning-navigation:window-navigation-api>navigation API</a>.<li><p>Let <var>entryListForFiring</var> be <var>formDataEntryList</var> if
     <var>documentResource</var> is a <a href=#post-resource id=beginning-navigation:post-resource-2>POST resource</a>; otherwise, null.<li><p>Let <var>navigationAPIStateForFiring</var> be <var>navigationAPIState</var> if
     <var>navigationAPIState</var> is not null; otherwise,
     <a id=beginning-navigation:structuredserializeforstorage href=structured-data.html#structuredserializeforstorage>StructuredSerializeForStorage</a>(undefined).<li><p>Let <var>continue</var> be the result of <a href=nav-history-apis.html#fire-a-push/replace/reload-navigate-event id=beginning-navigation:fire-a-push/replace/reload-navigate-event>firing a push/replace/reload <code>navigate</code>
     event</a> at <var>navigation</var> with <i id=beginning-navigation:fire-navigate-prr-navigationtype><a href=nav-history-apis.html#fire-navigate-prr-navigationtype>navigationType</a></i> set to <var>historyHandling</var>,
     <i id=beginning-navigation:fire-navigate-prr-issamedocument><a href=nav-history-apis.html#fire-navigate-prr-issamedocument>isSameDocument</a></i> set to false, <i id=beginning-navigation:fire-navigate-prr-userinvolvement><a href=nav-history-apis.html#fire-navigate-prr-userinvolvement>userInvolvement</a></i> set to
     <var>userInvolvement</var>, <i id=beginning-navigation:fire-navigate-prr-sourceelement><a href=nav-history-apis.html#fire-navigate-prr-sourceelement>sourceElement</a></i> set
     to <var>sourceElement</var>, <i id=beginning-navigation:fire-navigate-prr-formdataentrylist><a href=nav-history-apis.html#fire-navigate-prr-formdataentrylist>formDataEntryList</a></i> set to
     <var>entryListForFiring</var>, <i id=beginning-navigation:fire-navigate-prr-destinationurl><a href=nav-history-apis.html#fire-navigate-prr-destinationurl>destinationURL</a></i>
     set to <var>url</var>, and <i id=beginning-navigation:fire-navigate-prr-navigationapistate><a href=nav-history-apis.html#fire-navigate-prr-navigationapistate>navigationAPIState</a></i> set to
     <var>navigationAPIStateForFiring</var>.<li><p>If <var>continue</var> is false, then return.</p>
    </ol>

    <p class=note>It is possible for navigations with <var>userInvolvement</var> of "<code id=beginning-navigation:uni-browser-ui-4><a href=#uni-browser-ui>browser UI</a></code>" or initiated by a <a href=browsers.html#same-origin-domain id=beginning-navigation:same-origin-domain-2>cross origin-domain</a> <var>sourceDocument</var> to fire <code id=beginning-navigation:event-navigate><a href=indices.html#event-navigate>navigate</a></code> events, if they go through the earlier <a href=#navigate-fragid id=beginning-navigation:navigate-fragid-3>navigate to a fragment</a> path.</p>
   <li><p>If <var>sourceDocument</var> is <var>navigable</var>'s <a href=document-sequences.html#nav-container-document id=beginning-navigation:nav-container-document>container document</a>, then <a id=beginning-navigation:reserve-deferred-fetch-quota href=https://fetch.spec.whatwg.org/#reserve-deferred-fetch-quota data-x-internal=reserve-deferred-fetch-quota>reserve deferred fetch
   quota</a> for <var>navigable</var>'s <a href=document-sequences.html#nav-container id=beginning-navigation:nav-container-2>container</a> given
   <var>url</var>'s <a href=https://url.spec.whatwg.org/#concept-url-origin id=beginning-navigation:concept-url-origin data-x-internal=concept-url-origin>origin</a>.<li>
    <p><a id=beginning-navigation:in-parallel href=infrastructure.html#in-parallel>In parallel</a>, run these steps:</p>

    <ol><li><p>Let <var>unloadPromptCanceled</var> be the result of <a href=#checking-if-unloading-is-canceled id=beginning-navigation:checking-if-unloading-is-canceled>checking if unloading is
     canceled</a> for <var>navigable</var>'s <a href=document-sequences.html#nav-document id=beginning-navigation:nav-document-10>active
     document</a>'s <a id=beginning-navigation:inclusive-descendant-navigables href=document-sequences.html#inclusive-descendant-navigables>inclusive descendant navigables</a>.</p>

     <li>
      <p>If <var>unloadPromptCanceled</var> is not "<code>continue</code>", or
      <var>navigable</var>'s <a href=#ongoing-navigation id=beginning-navigation:ongoing-navigation-3>ongoing navigation</a> is no longer
      <var>navigationId</var>:</p>

      <ol><li><p>Invoke <a id=beginning-navigation:webdriver-bidi-navigation-failed-3 href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-navigation-failed data-x-internal=webdriver-bidi-navigation-failed>WebDriver BiDi navigation failed</a> with <var>navigable</var> and a
       new <a id=beginning-navigation:webdriver-bidi-navigation-status-4 href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-navigation-status data-x-internal=webdriver-bidi-navigation-status>WebDriver BiDi navigation status</a> whose <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-id id=beginning-navigation:navigation-status-id-4 data-x-internal=navigation-status-id>id</a> is <var>navigationId</var>, <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-status id=beginning-navigation:navigation-status-status-4 data-x-internal=navigation-status-status>status</a> is "<code id=beginning-navigation:navigation-status-canceled-3><a data-x-internal=navigation-status-canceled href=https://w3c.github.io/webdriver-bidi/#navigation-status-canceled>canceled</a></code>", and <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-url id=beginning-navigation:navigation-status-url-4 data-x-internal=navigation-status-url>url</a> is <var>url</var>.<li><p>Abort these steps.</ol>
     <li><p><a id=beginning-navigation:queue-a-global-task-3 href=webappapis.html#queue-a-global-task>Queue a global task</a> on the <a id=beginning-navigation:navigation-and-traversal-task-source-3 href=webappapis.html#navigation-and-traversal-task-source>navigation and traversal task
     source</a> given <var>navigable</var>'s <a href=document-sequences.html#nav-window id=beginning-navigation:nav-window-4>active window</a> to
     <a id=beginning-navigation:abort-a-document-and-its-descendants href=document-lifecycle.html#abort-a-document-and-its-descendants>abort a document and its descendants</a> given <var>navigable</var>'s <a href=document-sequences.html#nav-document id=beginning-navigation:nav-document-11>active document</a>.<li id=navigation-create-document-state>
      <p>Let <var>documentState</var> be a new <a href=#document-state-2 id=beginning-navigation:document-state-2>document state</a> with</p>

      <dl class=props><dt><a href=#document-state-request-referrer-policy id=beginning-navigation:document-state-request-referrer-policy>request referrer policy</a><dd><var>referrerPolicy</var><dt><a href=#document-state-initiator-origin id=beginning-navigation:document-state-initiator-origin>initiator origin</a><dd><var>initiatorOriginSnapshot</var><dt><a href=#document-state-resource id=beginning-navigation:document-state-resource>resource</a><dd><var>documentResource</var><dt><a href=#document-state-nav-target-name id=beginning-navigation:document-state-nav-target-name>navigable target name</a><dd><var>navigable</var>'s <a href=document-sequences.html#nav-target id=beginning-navigation:nav-target>target name</a></dl>

      <p class=note>The <a href=#document-state-nav-target-name id=beginning-navigation:document-state-nav-target-name-2>navigable target
      name</a> can get cleared under various conditions later in the navigation process, before
      the document state is finalized.</p>
     <li>
      <p>If <var>url</var> <a id=beginning-navigation:matches-about:blank href=urls-and-fetching.html#matches-about:blank>matches <code>about:blank</code></a> or
      is <code id=beginning-navigation:about:srcdoc><a href=urls-and-fetching.html#about:srcdoc>about:srcdoc</a></code>, then:</p>

      <ol><li><p>Set <var>documentState</var>'s <a href=#document-state-origin id=beginning-navigation:document-state-origin>origin</a> to
       <var>initiatorOriginSnapshot</var>.<li><p>Set <var>documentState</var>'s <a href=#document-state-about-base-url id=beginning-navigation:document-state-about-base-url>about base
       URL</a> to <var>initiatorBaseURLSnapshot</var>.</ol>
     <li><p>Let <var>historyEntry</var> be a new <a href=#session-history-entry id=beginning-navigation:session-history-entry>session history entry</a>, with its <a href=#she-url id=beginning-navigation:she-url-2>URL</a> set to <var>url</var> and its <a href=#she-document-state id=beginning-navigation:she-document-state>document state</a> set to
     <var>documentState</var>.<li><p>Let <var>navigationParams</var> be null.<li>
      <p>If <var>response</var> is non-null:</p>

      <p id=note-navigate-called-with-response class=note><a href=#note-navigate-called-with-response class=self-link></a>The <a href=#navigate id=beginning-navigation:navigate>navigate</a> algorithm
      is only supplied with a <a href=https://fetch.spec.whatwg.org/#concept-response id=beginning-navigation:concept-response-2 data-x-internal=concept-response>response</a> as part of the
      <code id=beginning-navigation:the-object-element><a href=iframe-embed-object.html#the-object-element>object</a></code> and <code id=beginning-navigation:the-embed-element><a href=iframe-embed-object.html#the-embed-element>embed</a></code> processing models, or for processing parts of
      <a href=document-lifecycle.html#navigate-multipart-x-mixed-replace id=beginning-navigation:navigate-multipart-x-mixed-replace><code>multipart/x-mixed-replace</code>
      responses</a> after the initial response.</p>

      <ol><li><p>Let <var>sourcePolicyContainer</var> be a <a href=browsers.html#clone-a-policy-container id=beginning-navigation:clone-a-policy-container>clone</a> of the <var>sourceDocument</var>'s <a href=dom.html#concept-document-policy-container id=beginning-navigation:concept-document-policy-container>policy container</a>, if
       <var>sourceDocument</var> is not null; otherwise null.<li><p>Let <var>policyContainer</var> be the result of <a href=browsers.html#determining-navigation-params-policy-container id=beginning-navigation:determining-navigation-params-policy-container>determining navigation params policy container</a> given
       <var>response</var>'s <a href=https://fetch.spec.whatwg.org/#concept-response-url id=beginning-navigation:concept-response-url data-x-internal=concept-response-url>URL</a>,
       null, <var>sourcePolicyContainer</var>, <var>navigable</var>'s <a href=document-sequences.html#nav-container-document id=beginning-navigation:nav-container-document-2>container document</a>'s <a href=dom.html#concept-document-policy-container id=beginning-navigation:concept-document-policy-container-2>policy container</a>, and null.<li><p>Let <var>finalSandboxFlags</var> be the <a href=https://infra.spec.whatwg.org/#set-union id=beginning-navigation:set-union data-x-internal=set-union>union</a> of
       <var>targetSnapshotParams</var>'s <a href=#target-snapshot-params-sandbox id=beginning-navigation:target-snapshot-params-sandbox>sandboxing
       flags</a> and <var>policyContainer</var>'s <a href=browsers.html#policy-container-csp-list id=beginning-navigation:policy-container-csp-list>CSP
       list</a>'s <a id=beginning-navigation:csp-derived-sandboxing-flags href=browsers.html#csp-derived-sandboxing-flags>CSP-derived sandboxing flags</a>.<li><p>Let <var>responseOrigin</var> be the result of <a id=beginning-navigation:determining-the-origin href=document-sequences.html#determining-the-origin>determining the origin</a>
       given <var>response</var>'s <a href=https://fetch.spec.whatwg.org/#concept-response-url id=beginning-navigation:concept-response-url-2 data-x-internal=concept-response-url>URL</a>,
       <var>finalSandboxFlags</var>, and <var>documentState</var>'s <a href=#document-state-initiator-origin id=beginning-navigation:document-state-initiator-origin-2>initiator origin</a>.<li><p>Let <var>coop</var> be a new <a id=beginning-navigation:cross-origin-opener-policy href=browsers.html#cross-origin-opener-policy>opener policy</a>.<li>
        <p>Let <var>coopEnforcementResult</var> be a new <a href=browsers.html#coop-enforcement-result id=beginning-navigation:coop-enforcement-result>opener policy enforcement result</a>
        with</p>

        <dl class=props><dt><a href=browsers.html#coop-enforcement-url id=beginning-navigation:coop-enforcement-url>url</a><dd><var>response</var>'s <a href=https://fetch.spec.whatwg.org/#concept-response-url id=beginning-navigation:concept-response-url-3 data-x-internal=concept-response-url>URL</a><dt><a href=browsers.html#coop-enforcement-origin id=beginning-navigation:coop-enforcement-origin>origin</a><dd><var>responseOrigin</var><dt><a href=browsers.html#coop-enforcement-coop id=beginning-navigation:coop-enforcement-coop>opener policy</a><dd><var>coop</var></dl>
       <li>
        <p>Set <var>navigationParams</var> to a new <a href=#navigation-params id=beginning-navigation:navigation-params>navigation params</a>, with</p>

        <dl class=props><dt><a href=#navigation-params-id id=beginning-navigation:navigation-params-id>id</a><dd><var>navigationId</var><dt><a href=#navigation-params-navigable id=beginning-navigation:navigation-params-navigable>navigable</a><dd><var>navigable</var><dt><a href=#navigation-params-request id=beginning-navigation:navigation-params-request>request</a><dd>null<dt><a href=#navigation-params-response id=beginning-navigation:navigation-params-response>response</a><dd><var>response</var><dt><a href=#navigation-params-fetch-controller id=beginning-navigation:navigation-params-fetch-controller>fetch controller</a><dd>null<dt><a href=#navigation-params-commit-early-hints id=beginning-navigation:navigation-params-commit-early-hints>commit early hints</a><dd>null<dt><a href=#navigation-params-coop-enforcement-result id=beginning-navigation:navigation-params-coop-enforcement-result>COOP enforcement result</a><dd><var>coopEnforcementResult</var><dt><a href=#navigation-params-reserved-environment id=beginning-navigation:navigation-params-reserved-environment>reserved environment</a><dd>null<dt><a href=#navigation-params-origin id=beginning-navigation:navigation-params-origin>origin</a><dd><var>responseOrigin</var><dt><a href=#navigation-params-policy-container id=beginning-navigation:navigation-params-policy-container>policy container</a><dd><var>policyContainer</var><dt><a href=#navigation-params-sandboxing id=beginning-navigation:navigation-params-sandboxing>final sandboxing flag set</a><dd><var>finalSandboxFlags</var><dt><a href=#navigation-params-coop id=beginning-navigation:navigation-params-coop>opener policy</a><dd><var>coop</var><dt><a href=#navigation-params-nav-timing-type id=beginning-navigation:navigation-params-nav-timing-type>navigation timing type</a><dd>"<code id=beginning-navigation:dom-navigationtimingtype-navigate><a data-x-internal=dom-navigationtimingtype-navigate href=https://w3c.github.io/navigation-timing/#dom-navigationtimingtype-navigate>navigate</a></code>"<dt><a href=#navigation-params-about-base-url id=beginning-navigation:navigation-params-about-base-url>about base URL</a><dd><var>documentState</var>'s <a href=#document-state-about-base-url id=beginning-navigation:document-state-about-base-url-2>about base
         URL</a><dt><a href=#navigation-params-user-involvement id=beginning-navigation:navigation-params-user-involvement>user involvement</a><dd><var>userInvolvement</var></dl>
       </ol>
     <li>
      <p><a href="#attempt-to-populate-the-history-entry's-document" id="beginning-navigation:attempt-to-populate-the-history-entry's-document">Attempt to populate the history entry's document</a> for <var>historyEntry</var>,
      given <var>navigable</var>, "<code id=beginning-navigation:dom-navigationtimingtype-navigate-2><a data-x-internal=dom-navigationtimingtype-navigate href=https://w3c.github.io/navigation-timing/#dom-navigationtimingtype-navigate>navigate</a></code>", <var>sourceSnapshotParams</var>,
      <var>targetSnapshotParams</var>, <var>userInvolvement</var>, <var>navigationId</var>,
      <var>navigationParams</var>, <var>cspNavigationType</var>, with <i id=beginning-navigation:attempt-to-populate-allow-post><a href=#attempt-to-populate-allow-post>allowPOST</a></i> set to true and <i id=beginning-navigation:attempt-to-populate-completion-steps><a href=#attempt-to-populate-completion-steps>completionSteps</a></i> set to the following
      step:</p>

      <ol><li><p><a href=#tn-append-session-history-traversal-steps id=beginning-navigation:tn-append-session-history-traversal-steps>Append session history
       traversal steps</a> to <var>navigable</var>'s <a href=document-sequences.html#nav-traversable id=beginning-navigation:nav-traversable>traversable</a> to <a href=#finalize-a-cross-document-navigation id=beginning-navigation:finalize-a-cross-document-navigation>finalize a cross-document
       navigation</a> given <var>navigable</var>, <var>historyHandling</var>,
       <var>userInvolvement</var>, and <var>historyEntry</var>.</ol>
     </ol>
   </ol>


  <h5 id=ending-navigation><span class=secno>7.4.2.3</span> Ending navigation<a href=#ending-navigation class=self-link></a></h5>

  <p>Although the usual cross-document navigation case will first foray into <a href=#populating-a-session-history-entry>populating a session history entry</a> with a
  <code id=ending-navigation:document><a href=dom.html#document>Document</a></code>, all navigations that don't get aborted will ultimately end up calling into
  one of the below algorithms.</p>


  <h6 id=the-usual-cross-document-navigation-case><span class=secno>7.4.2.3.1</span> The usual cross-document navigation case<a href=#the-usual-cross-document-navigation-case class=self-link></a></h6>

  <p>To <dfn id=finalize-a-cross-document-navigation>finalize a cross-document navigation</dfn> given a <a id=the-usual-cross-document-navigation-case:navigable href=document-sequences.html#navigable>navigable</a>
  <var>navigable</var>, a <a href=#history-handling-behavior id=the-usual-cross-document-navigation-case:history-handling-behavior>history handling behavior</a> <var>historyHandling</var>, a
  <a href=#user-navigation-involvement id=the-usual-cross-document-navigation-case:user-navigation-involvement>user navigation involvement</a> <var>userInvolvement</var>, and a <a href=#session-history-entry id=the-usual-cross-document-navigation-case:session-history-entry>session history
  entry</a> <var>historyEntry</var>:</p>

  <ol><li><p><a id=the-usual-cross-document-navigation-case:assert href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: this is running on <var>navigable</var>'s <a href=document-sequences.html#nav-traversable id=the-usual-cross-document-navigation-case:nav-traversable>traversable navigable's</a> <a href=document-sequences.html#tn-session-history-traversal-queue id=the-usual-cross-document-navigation-case:tn-session-history-traversal-queue>session history traversal queue</a>.<li><p>Set <var>navigable</var>'s <a id=the-usual-cross-document-navigation-case:delaying-load-events-mode href=document-sequences.html#delaying-load-events-mode>is delaying <code>load</code>
   events</a> to false.<li>
    <p>If <var>historyEntry</var>'s <a href=#she-document id=the-usual-cross-document-navigation-case:she-document>document</a> is null, then
    return.</p>

    <p class=note>This means that <a href="#attempt-to-populate-the-history-entry's-document" id="the-usual-cross-document-navigation-case:attempt-to-populate-the-history-entry's-document">attempting to populate the history entry's document</a> ended up not creating a
    document, as a result of e.g., the navigation being canceled by a subsequent navigation, a 204
    No Content response, etc.</p>
   <li id=resetBCName>
    <p>If all of the following are true:</p>

    <ul><li><p><var>navigable</var>'s <a href=document-sequences.html#nav-parent id=the-usual-cross-document-navigation-case:nav-parent>parent</a> is null;<li><p><var>historyEntry</var>'s <a href=#she-document id=the-usual-cross-document-navigation-case:she-document-2>document</a>'s <a href=document-sequences.html#concept-document-bc id=the-usual-cross-document-navigation-case:concept-document-bc>browsing context</a> is not an <a id=the-usual-cross-document-navigation-case:auxiliary-browsing-context href=document-sequences.html#auxiliary-browsing-context>auxiliary browsing
     context</a> whose <a id=the-usual-cross-document-navigation-case:opener-browsing-context href=document-sequences.html#opener-browsing-context>opener browsing context</a> is non-null; and<li><p><var>historyEntry</var>'s <a href=#she-document id=the-usual-cross-document-navigation-case:she-document-3>document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=the-usual-cross-document-navigation-case:concept-document-origin data-x-internal=concept-document-origin>origin</a> is not <var>navigable</var>'s <a href=document-sequences.html#nav-document id=the-usual-cross-document-navigation-case:nav-document>active document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=the-usual-cross-document-navigation-case:concept-document-origin-2 data-x-internal=concept-document-origin>origin</a>,</ul>

    <p>then set <var>historyEntry</var>'s <a href=#she-document-state id=the-usual-cross-document-navigation-case:she-document-state>document state</a>'s
    <a href=#document-state-nav-target-name id=the-usual-cross-document-navigation-case:document-state-nav-target-name>navigable target name</a> to the empty
    string.</p>
   <li><p>Let <var>entryToReplace</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=the-usual-cross-document-navigation-case:nav-active-history-entry>active session history entry</a> if
   <var>historyHandling</var> is "<code id=the-usual-cross-document-navigation-case:navigationhistorybehavior-replace><a href=#navigationhistorybehavior-replace>replace</a></code>",
   otherwise null.<li><p>Let <var>traversable</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-traversable id=the-usual-cross-document-navigation-case:nav-traversable-2>traversable navigable</a>.<li><p>Let <var>targetStep</var> be null.<li><p>Let <var>targetEntries</var> be the result of <a href=#getting-session-history-entries id=the-usual-cross-document-navigation-case:getting-session-history-entries>getting session history
   entries</a> for <var>navigable</var>.<li>
    <p>If <var>entryToReplace</var> is null, then:</p>

    <ol><li><p><a href=#clear-the-forward-session-history id=the-usual-cross-document-navigation-case:clear-the-forward-session-history>Clear the forward session history</a> of <var>traversable</var>.<li><p>Set <var>targetStep</var> to <var>traversable</var>'s <a href=document-sequences.html#tn-current-session-history-step id=the-usual-cross-document-navigation-case:tn-current-session-history-step>current session history step</a> + 1.<li><p>Set <var>historyEntry</var>'s <a href=#she-step id=the-usual-cross-document-navigation-case:she-step>step</a> to
     <var>targetStep</var>.<li><p><a href=https://infra.spec.whatwg.org/#list-append id=the-usual-cross-document-navigation-case:list-append data-x-internal=list-append>Append</a> <var>historyEntry</var> to
     <var>targetEntries</var>.</ol>

    <p>Otherwise:</p>

    <ol><li><p><a href=https://infra.spec.whatwg.org/#list-replace id=the-usual-cross-document-navigation-case:list-replace data-x-internal=list-replace>Replace</a> <var>entryToReplace</var> with
     <var>historyEntry</var> in <var>targetEntries</var>.<li><p>Set <var>historyEntry</var>'s <a href=#she-step id=the-usual-cross-document-navigation-case:she-step-2>step</a> to
     <var>entryToReplace</var>'s <a href=#she-step id=the-usual-cross-document-navigation-case:she-step-3>step</a>.<li><p>If <var>historyEntry</var>'s <a href=#she-document-state id=the-usual-cross-document-navigation-case:she-document-state-2>document state</a>'s
     <a href=#document-state-origin id=the-usual-cross-document-navigation-case:document-state-origin>origin</a> is <a id=the-usual-cross-document-navigation-case:same-origin href=browsers.html#same-origin>same origin</a> with
     <var>entryToReplace</var>'s <a href=#she-document-state id=the-usual-cross-document-navigation-case:she-document-state-3>document state</a>'s <a href=#document-state-origin id=the-usual-cross-document-navigation-case:document-state-origin-2>origin</a>, then set <var>historyEntry</var>'s <a href=#she-navigation-api-key id=the-usual-cross-document-navigation-case:she-navigation-api-key>navigation API key</a> to <var>entryToReplace</var>'s <a href=#she-navigation-api-key id=the-usual-cross-document-navigation-case:she-navigation-api-key-2>navigation API key</a>.<li><p>Set <var>targetStep</var> to <var>traversable</var>'s <a href=document-sequences.html#tn-current-session-history-step id=the-usual-cross-document-navigation-case:tn-current-session-history-step-2>current session history step</a>.</ol>
   <li><p><a href=#apply-the-push/replace-history-step id=the-usual-cross-document-navigation-case:apply-the-push/replace-history-step>Apply the push/replace history step</a> <var>targetStep</var> to
   <var>traversable</var> given <var>historyHandling</var> and <var>userInvolvement</var>.</ol>


  <h6 id=the-javascript:-url-special-case><span class=secno>7.4.2.3.2</span> <dfn>The <code>javascript:</code> URL special case</dfn><a href=#the-javascript:-url-special-case class=self-link></a></h6>

  <p class=XXX><code id=the-javascript:-url-special-case:the-javascript:-url-special-case><a href=#the-javascript:-url-special-case>javascript:</a></code> URLs have a <a href=https://github.com/whatwg/html/labels/topic%3A javascript%3A URLs>dedicated label</a>
  on the issue tracker documenting various problems with their specification.</p>

  <p>To <dfn id=navigate-to-a-javascript:-url>navigate to a <code>javascript:</code> URL</dfn>, given a <a id=the-javascript:-url-special-case:navigable href=document-sequences.html#navigable>navigable</a>
  <var>targetNavigable</var>, a <a id=the-javascript:-url-special-case:url href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> <var>url</var>, a <a href=#history-handling-behavior id=the-javascript:-url-special-case:history-handling-behavior>history handling
  behavior</a> <var>historyHandling</var>, a <a href=#source-snapshot-params id=the-javascript:-url-special-case:source-snapshot-params>source snapshot params</a>
  <var>sourceSnapshotParams</var>, an <a id=the-javascript:-url-special-case:concept-origin href=browsers.html#concept-origin>origin</a> <var>initiatorOrigin</var>, a <a href=#user-navigation-involvement id=the-javascript:-url-special-case:user-navigation-involvement>user
  navigation involvement</a> <var>userInvolvement</var>, a string
  <var>cspNavigationType</var>, and a boolean <var>initialInsertion</var>:</p>

  <ol><li><p><a id=the-javascript:-url-special-case:assert href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>historyHandling</var> is "<code id=the-javascript:-url-special-case:navigationhistorybehavior-replace><a href=#navigationhistorybehavior-replace>replace</a></code>".<li><p><a href=#set-the-ongoing-navigation id=the-javascript:-url-special-case:set-the-ongoing-navigation>Set the ongoing navigation</a> for <var>targetNavigable</var> to null.<li><p>If <var>initiatorOrigin</var> is not <a id=the-javascript:-url-special-case:same-origin-domain href=browsers.html#same-origin-domain>same origin-domain</a> with
   <var>targetNavigable</var>'s <a href=document-sequences.html#nav-document id=the-javascript:-url-special-case:nav-document>active document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=the-javascript:-url-special-case:concept-document-origin data-x-internal=concept-document-origin>origin</a>, then return.<li>
    <p>Let <var>request</var> be a new <a href=https://fetch.spec.whatwg.org/#concept-request id=the-javascript:-url-special-case:concept-request data-x-internal=concept-request>request</a> whose <a href=https://fetch.spec.whatwg.org/#concept-request-url id=the-javascript:-url-special-case:concept-request-url data-x-internal=concept-request-url>URL</a> is <var>url</var> and whose <a href=https://fetch.spec.whatwg.org/#concept-request-policy-container id=the-javascript:-url-special-case:concept-request-policy-container data-x-internal=concept-request-policy-container>policy container</a> is
    <var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-policy-container id=the-javascript:-url-special-case:source-snapshot-params-policy-container>source
    policy container</a>.</p>

    <p class=note>This is a synthetic <a href=https://fetch.spec.whatwg.org/#concept-request id=the-javascript:-url-special-case:concept-request-2 data-x-internal=concept-request>request</a> solely for
    plumbing into the next step. It will never hit the network.</p>
   <li><p>If the result of <a id=the-javascript:-url-special-case:should-navigation-request-of-type-be-blocked-by-content-security-policy href=https://w3c.github.io/webappsec-csp/#should-block-navigation-request data-x-internal=should-navigation-request-of-type-be-blocked-by-content-security-policy>should navigation request of type be blocked by Content Security
   Policy?</a> given <var>request</var> and <var>cspNavigationType</var> is "<code>Blocked</code>", then return. <a href=references.html#refsCSP>[CSP]</a><li><p>Let <var>newDocument</var> be the result of <a href=#evaluate-a-javascript:-url id=the-javascript:-url-special-case:evaluate-a-javascript:-url>evaluating a <code>javascript:</code> URL</a> given <var>targetNavigable</var>,
   <var>url</var>, <var>initiatorOrigin</var>, and <var>userInvolvement</var>.<li>
    <p>If <var>newDocument</var> is null:</p>

    <ol><li><p>If <var>initialInsertion</var> is true and <var>targetNavigable</var>'s <a href=document-sequences.html#nav-document id=the-javascript:-url-special-case:nav-document-2>active document</a>'s <a id=the-javascript:-url-special-case:is-initial-about:blank href=dom.html#is-initial-about:blank>is initial
     <code>about:blank</code></a> is true, then run the <a id=the-javascript:-url-special-case:iframe-load-event-steps href=iframe-embed-object.html#iframe-load-event-steps>iframe load event steps</a>
     given <var>targetNavigable</var>'s <a href=document-sequences.html#nav-container id=the-javascript:-url-special-case:nav-container>container</a>.<li><p>Return.</ol>

    <p class=note>In this case, some JavaScript code was executed, but no new
    <code id=the-javascript:-url-special-case:document><a href=dom.html#document>Document</a></code> was created, so we will not perform a navigation.</p>
   <li><p><a id=the-javascript:-url-special-case:assert-2 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>initiatorOrigin</var> is <var>newDocument</var>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=the-javascript:-url-special-case:concept-document-origin-2 data-x-internal=concept-document-origin>origin</a>.<li><p>Let <var>entryToReplace</var> be <var>targetNavigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=the-javascript:-url-special-case:nav-active-history-entry>active session history entry</a>.<li><p>Let <var>oldDocState</var> be <var>entryToReplace</var>'s <a href=#she-document-state id=the-javascript:-url-special-case:she-document-state>document state</a>.<li>
    <p>Let <var>documentState</var> be a new <a href=#document-state-2 id=the-javascript:-url-special-case:document-state-2>document state</a> with</p>

    <dl class=props><dt><a href=#document-state-document id=the-javascript:-url-special-case:document-state-document>document</a><dd><var>newDocument</var><dt><a href=#document-state-history-policy-container id=the-javascript:-url-special-case:document-state-history-policy-container>history policy container</a><dd>a <a href=browsers.html#clone-a-policy-container id=the-javascript:-url-special-case:clone-a-policy-container>clone</a> of the <var>oldDocState</var>'s
     <a href=#document-state-history-policy-container id=the-javascript:-url-special-case:document-state-history-policy-container-2>history policy container</a> if it is
     non-null; null otherwise<dt><a href=#document-state-request-referrer id=the-javascript:-url-special-case:document-state-request-referrer>request referrer</a><dd><var>oldDocState</var>'s <a href=#document-state-request-referrer id=the-javascript:-url-special-case:document-state-request-referrer-2>request
     referrer</a><dt><a href=#document-state-request-referrer-policy id=the-javascript:-url-special-case:document-state-request-referrer-policy>request referrer policy</a><dd><var>oldDocState</var>'s <a href=#document-state-request-referrer-policy id=the-javascript:-url-special-case:document-state-request-referrer-policy-2>request
     referrer policy</a> <span class=XXX>or should this be the <var>referrerPolicy</var> that
     was passed to <a href=#navigate id=the-javascript:-url-special-case:navigate>navigate</a>?</span><dt><a href=#document-state-initiator-origin id=the-javascript:-url-special-case:document-state-initiator-origin>initiator origin</a><dd><var>initiatorOrigin</var><dt><a href=#document-state-origin id=the-javascript:-url-special-case:document-state-origin>origin</a><dd><var>initiatorOrigin</var><dt><a href=#document-state-about-base-url id=the-javascript:-url-special-case:document-state-about-base-url>about base URL</a><dd><var>oldDocState</var>'s <a href=#document-state-about-base-url id=the-javascript:-url-special-case:document-state-about-base-url-2>about base
     URL</a><dt><a href=#document-state-resource id=the-javascript:-url-special-case:document-state-resource>resource</a><dd>null<dt><a href=#document-state-ever-populated id=the-javascript:-url-special-case:document-state-ever-populated>ever populated</a><dd>true<dt><a href=#document-state-nav-target-name id=the-javascript:-url-special-case:document-state-nav-target-name>navigable target name</a><dd><var>oldDocState</var>'s <a href=#document-state-nav-target-name id=the-javascript:-url-special-case:document-state-nav-target-name-2>navigable target
     name</a></dl>
   <li>
    <p>Let <var>historyEntry</var> be a new <a href=#session-history-entry id=the-javascript:-url-special-case:session-history-entry>session history entry</a>, with</p>

    <dl class=props><dt><a href=#she-url id=the-javascript:-url-special-case:she-url>URL</a><dd><var>entryToReplace</var>'s <a href=#she-url id=the-javascript:-url-special-case:she-url-2>URL</a><dt><a href=#she-document-state id=the-javascript:-url-special-case:she-document-state-2>document state</a><dd><var>documentState</var></dl>

    <p class=note>For the <a href=#she-url id=the-javascript:-url-special-case:she-url-3>URL</a>, we do <em>not</em> use
    <var>url</var>, i.e. the actual <code id=the-javascript:-url-special-case:the-javascript:-url-special-case-2><a href=#the-javascript:-url-special-case>javascript:</a></code> URL that
    the <a href=#navigate id=the-javascript:-url-special-case:navigate-2>navigate</a> algorithm was called with. This means <code id=the-javascript:-url-special-case:the-javascript:-url-special-case-3><a href=#the-javascript:-url-special-case>javascript:</a></code> URLs are never stored in session history, and so can never be
    traversed to.</p>
   <li><p><a href=#tn-append-session-history-traversal-steps id=the-javascript:-url-special-case:tn-append-session-history-traversal-steps>Append session history traversal
   steps</a> to <var>targetNavigable</var>'s <a href=document-sequences.html#nav-traversable id=the-javascript:-url-special-case:nav-traversable>traversable</a>
   to <a href=#finalize-a-cross-document-navigation id=the-javascript:-url-special-case:finalize-a-cross-document-navigation>finalize a cross-document navigation</a> with <var>targetNavigable</var>,
   <var>historyHandling</var>, <var>userInvolvement</var>, and <var>historyEntry</var>.</ol>

  <p>To <dfn id=evaluate-a-javascript:-url>evaluate a <code>javascript:</code> URL</dfn> given a <a id=the-javascript:-url-special-case:navigable-2 href=document-sequences.html#navigable>navigable</a>
  <var>targetNavigable</var>, a <a id=the-javascript:-url-special-case:url-2 href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> <var>url</var>, an <a id=the-javascript:-url-special-case:concept-origin-2 href=browsers.html#concept-origin>origin</a>
  <var>newDocumentOrigin</var>, and a <a href=#user-navigation-involvement id=the-javascript:-url-special-case:user-navigation-involvement-2>user navigation involvement</a>
  <var>userInvolvement</var>:</p>

  <ol><li><p>Let <var>urlString</var> be the result of running the <a href=https://url.spec.whatwg.org/#concept-url-serializer id=the-javascript:-url-special-case:concept-url-serializer data-x-internal=concept-url-serializer>URL serializer</a> on <var>url</var>.<li><p>Let <var>encodedScriptSource</var> be the result of removing the leading "<code>javascript:</code>" from <var>urlString</var>.<li><p>Let <var>scriptSource</var> be the <a href=https://encoding.spec.whatwg.org/#utf-8-decode id=the-javascript:-url-special-case:utf-8-decode data-x-internal=utf-8-decode>UTF-8 decoding</a> of
   the <a href=https://url.spec.whatwg.org/#string-percent-decode id=the-javascript:-url-special-case:percent-decode data-x-internal=percent-decode>percent-decoding</a> of
   <var>encodedScriptSource</var>.<li><p>Let <var>settings</var> be <var>targetNavigable</var>'s <a href=document-sequences.html#nav-document id=the-javascript:-url-special-case:nav-document-3>active document</a>'s <a id=the-javascript:-url-special-case:relevant-settings-object href=webappapis.html#relevant-settings-object>relevant settings object</a>.<li><p>Let <var>baseURL</var> be <var>settings</var>'s <a id=the-javascript:-url-special-case:api-base-url href=webappapis.html#api-base-url>API base URL</a>.<li><p>Let <var>script</var> be the result of <a id=the-javascript:-url-special-case:creating-a-classic-script href=webappapis.html#creating-a-classic-script>creating a classic script</a> given
   <var>scriptSource</var>, <var>settings</var>, <var>baseURL</var>, and the <a id=the-javascript:-url-special-case:default-script-fetch-options href=webappapis.html#default-script-fetch-options>default script
   fetch options</a>.<li><p>Let <var>evaluationStatus</var> be the result of <a href=webappapis.html#run-a-classic-script id=the-javascript:-url-special-case:run-a-classic-script>running the classic script</a> <var>script</var>.<li><p>Let <var>result</var> be null.<li><p>If <var>evaluationStatus</var> is a normal completion, and
   <var>evaluationStatus</var>.[[Value]] is a String, then set <var>result</var> to
   <var>evaluationStatus</var>.[[Value]].<li><p>Otherwise, return null.<li>
    <p>Let <var>response</var> be a new <a href=https://fetch.spec.whatwg.org/#concept-response id=the-javascript:-url-special-case:concept-response data-x-internal=concept-response>response</a> with</p>

    <dl class=props><dt><a href=https://fetch.spec.whatwg.org/#concept-response-url id=the-javascript:-url-special-case:concept-response-url data-x-internal=concept-response-url>URL</a><dd><var>targetNavigable</var>'s <a href=document-sequences.html#nav-document id=the-javascript:-url-special-case:nav-document-4>active document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-url id="the-javascript:-url-special-case:the-document's-address" data-x-internal="the-document's-address">URL</a><dt><a href=https://fetch.spec.whatwg.org/#concept-response-header-list id=the-javascript:-url-special-case:concept-response-header-list data-x-internal=concept-response-header-list>header list</a><dd>« (`<code id=the-javascript:-url-special-case:content-type><a href=urls-and-fetching.html#content-type>Content-Type</a></code>`, `<code>text/html;charset=utf-8</code>`) »<dt><a href=https://fetch.spec.whatwg.org/#concept-response-body id=the-javascript:-url-special-case:concept-response-body data-x-internal=concept-response-body>body</a><dd>the <a href=https://encoding.spec.whatwg.org/#utf-8-encode id=the-javascript:-url-special-case:utf-8-encode data-x-internal=utf-8-encode>UTF-8 encoding</a> of <var>result</var>, <a id=the-javascript:-url-special-case:as-a-body href=https://fetch.spec.whatwg.org/#byte-sequence-as-a-body data-x-internal=as-a-body>as a
     body</a></dl>

    <p class=note>The encoding to UTF-8 means that unpaired <a href=https://infra.spec.whatwg.org/#surrogate id=the-javascript:-url-special-case:surrogate data-x-internal=surrogate>surrogates</a> will not roundtrip, once the HTML parser decodes the
    response body.</p>
   <li><p>Let <var>policyContainer</var> be <var>targetNavigable</var>'s <a href=document-sequences.html#nav-document id=the-javascript:-url-special-case:nav-document-5>active document</a>'s <a href=dom.html#concept-document-policy-container id=the-javascript:-url-special-case:concept-document-policy-container>policy container</a>.</p>

   <li><p>Let <var>finalSandboxFlags</var> be <var>policyContainer</var>'s <a href=browsers.html#policy-container-csp-list id=the-javascript:-url-special-case:policy-container-csp-list>CSP list</a>'s <a id=the-javascript:-url-special-case:csp-derived-sandboxing-flags href=browsers.html#csp-derived-sandboxing-flags>CSP-derived sandboxing
   flags</a>.<li><p>Let <var>coop</var> be <var>targetNavigable</var>'s <a href=document-sequences.html#nav-document id=the-javascript:-url-special-case:nav-document-6>active
   document</a>'s <a href=dom.html#concept-document-coop id=the-javascript:-url-special-case:concept-document-coop>opener policy</a>.<li>
    <p>Let <var>coopEnforcementResult</var> be a new <a href=browsers.html#coop-enforcement-result id=the-javascript:-url-special-case:coop-enforcement-result>opener
    policy enforcement result</a> with</p>

    <dl class=props><dt><a href=browsers.html#coop-enforcement-url id=the-javascript:-url-special-case:coop-enforcement-url>url</a><dd><var>url</var><dt><a href=browsers.html#coop-enforcement-origin id=the-javascript:-url-special-case:coop-enforcement-origin>origin</a><dd><var>newDocumentOrigin</var><dt><a href=browsers.html#coop-enforcement-coop id=the-javascript:-url-special-case:coop-enforcement-coop>opener policy</a><dd><var>coop</var></dl>
   <li>
    <p>Let <var>navigationParams</var> be a new <a href=#navigation-params id=the-javascript:-url-special-case:navigation-params>navigation params</a>, with</p>

    <dl class=props><dt><a href=#navigation-params-id id=the-javascript:-url-special-case:navigation-params-id>id</a><dd><var>navigationId</var><dt><a href=#navigation-params-navigable id=the-javascript:-url-special-case:navigation-params-navigable>navigable</a><dd><var>targetNavigable</var><dt><a href=#navigation-params-request id=the-javascript:-url-special-case:navigation-params-request>request</a><dd>null <span class=XXX>this will cause the referrer of the resulting <code id=the-javascript:-url-special-case:document-2><a href=dom.html#document>Document</a></code>
     to be null; is that correct?</span><dt><a href=#navigation-params-response id=the-javascript:-url-special-case:navigation-params-response>response</a><dd><var>response</var><dt><a href=#navigation-params-fetch-controller id=the-javascript:-url-special-case:navigation-params-fetch-controller>fetch controller</a><dd>null<dt><a href=#navigation-params-commit-early-hints id=the-javascript:-url-special-case:navigation-params-commit-early-hints>commit early hints</a><dd>null<dt><a href=#navigation-params-coop-enforcement-result id=the-javascript:-url-special-case:navigation-params-coop-enforcement-result>COOP enforcement result</a><dd><var>coopEnforcementResult</var><dt><a href=#navigation-params-reserved-environment id=the-javascript:-url-special-case:navigation-params-reserved-environment>reserved environment</a><dd>null<dt><a href=#navigation-params-origin id=the-javascript:-url-special-case:navigation-params-origin>origin</a><dd><var>newDocumentOrigin</var><dt><a href=#navigation-params-policy-container id=the-javascript:-url-special-case:navigation-params-policy-container>policy container</a><dd><var>policyContainer</var><dt><a href=#navigation-params-sandboxing id=the-javascript:-url-special-case:navigation-params-sandboxing>final sandboxing flag set</a><dd><var>finalSandboxFlags</var><dt><a href=#navigation-params-coop id=the-javascript:-url-special-case:navigation-params-coop>opener policy</a><dd><var>coop</var><dt><a href=#navigation-params-nav-timing-type id=the-javascript:-url-special-case:navigation-params-nav-timing-type>navigation timing type</a><dd>"<code id=the-javascript:-url-special-case:dom-navigationtimingtype-navigate><a data-x-internal=dom-navigationtimingtype-navigate href=https://w3c.github.io/navigation-timing/#dom-navigationtimingtype-navigate>navigate</a></code>"<dt><a href=#navigation-params-about-base-url id=the-javascript:-url-special-case:navigation-params-about-base-url>about base URL</a><dd><var>targetNavigable</var>'s <a href=document-sequences.html#nav-document id=the-javascript:-url-special-case:nav-document-7>active document</a>'s <a href=dom.html#concept-document-about-base-url id=the-javascript:-url-special-case:concept-document-about-base-url>about base URL</a><dt><a href=#navigation-params-user-involvement id=the-javascript:-url-special-case:navigation-params-user-involvement>user involvement</a><dd><var>userInvolvement</var></dl>
   <li><p>Return the result of <a href=document-lifecycle.html#navigate-html id=the-javascript:-url-special-case:navigate-html>loading an HTML document</a> given
   <var>navigationParams</var>.</ol>


  <h6 id=scroll-to-fragid><span class=secno>7.4.2.3.3</span> Fragment navigations<a href=#scroll-to-fragid class=self-link></a></h6>

  <p>To <dfn id=navigate-fragid>navigate to a fragment</dfn> given a <a id=scroll-to-fragid:navigable href=document-sequences.html#navigable>navigable</a>
  <var>navigable</var>, a <a id=scroll-to-fragid:url href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> <var>url</var>, a <a href=#history-handling-behavior id=scroll-to-fragid:history-handling-behavior>history handling behavior</a>
  <var>historyHandling</var>, a <a href=#user-navigation-involvement id=scroll-to-fragid:user-navigation-involvement>user navigation involvement</a> <var>userInvolvement</var>,
  an <code id=scroll-to-fragid:element><a data-x-internal=element href=https://dom.spec.whatwg.org/#interface-element>Element</a></code>-or-null <var>sourceElement</var>, a <a href=#serialized-state id=scroll-to-fragid:serialized-state>serialized state</a>-or-null
  <var>navigationAPIState</var>, and a <a href=#navigation-id id=scroll-to-fragid:navigation-id>navigation ID</a> <var>navigationId</var>:</p>

  <ol><li><p>Let <var>navigation</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-window id=scroll-to-fragid:nav-window>active
   window</a>'s <a href=nav-history-apis.html#window-navigation-api id=scroll-to-fragid:window-navigation-api>navigation API</a>.<li><p>Let <var>destinationNavigationAPIState</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=scroll-to-fragid:nav-active-history-entry>active session history entry</a>'s <a href=#she-navigation-api-state id=scroll-to-fragid:she-navigation-api-state>navigation API state</a>.<li><p>If <var>navigationAPIState</var> is not null, then set
   <var>destinationNavigationAPIState</var> to <var>navigationAPIState</var>.<li><p>Let <var>continue</var> be the result of <a href=nav-history-apis.html#fire-a-push/replace/reload-navigate-event id=scroll-to-fragid:fire-a-push/replace/reload-navigate-event>firing a push/replace/reload <code>navigate</code> event</a> at
   <var>navigation</var> with <i id=scroll-to-fragid:fire-navigate-prr-navigationtype><a href=nav-history-apis.html#fire-navigate-prr-navigationtype>navigationType</a></i> set to
   <var>historyHandling</var>, <i id=scroll-to-fragid:fire-navigate-prr-issamedocument><a href=nav-history-apis.html#fire-navigate-prr-issamedocument>isSameDocument</a></i> set
   to true, <i id=scroll-to-fragid:fire-navigate-prr-userinvolvement><a href=nav-history-apis.html#fire-navigate-prr-userinvolvement>userInvolvement</a></i> set to
   <var>userInvolvement</var>, <i id=scroll-to-fragid:fire-navigate-prr-sourceelement><a href=nav-history-apis.html#fire-navigate-prr-sourceelement>sourceElement</a></i> set
   to <var>sourceElement</var>, <i id=scroll-to-fragid:fire-navigate-prr-destinationurl><a href=nav-history-apis.html#fire-navigate-prr-destinationurl>destinationURL</a></i>
   set to <var>url</var>, and <i id=scroll-to-fragid:fire-navigate-prr-navigationapistate><a href=nav-history-apis.html#fire-navigate-prr-navigationapistate>navigationAPIState</a></i> set to
   <var>destinationNavigationAPIState</var>.<li><p>If <var>continue</var> is false, then return.</p>

   <li>
    <p>Let <var>historyEntry</var> be a new <a href=#session-history-entry id=scroll-to-fragid:session-history-entry>session history entry</a>, with</p>

    <dl class=props><dt><a href=#she-url id=scroll-to-fragid:she-url>URL</a><dd><var>url</var><dt><a href=#she-document-state id=scroll-to-fragid:she-document-state>document state</a><dd><var>navigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=scroll-to-fragid:nav-active-history-entry-2>active session history
     entry</a>'s <a href=#she-document-state id=scroll-to-fragid:she-document-state-2>document state</a><dt><a href=#she-navigation-api-state id=scroll-to-fragid:she-navigation-api-state-2>navigation API state</a><dd><var>destinationNavigationAPIState</var><dt><a href=#she-scroll-restoration-mode id=scroll-to-fragid:she-scroll-restoration-mode>scroll restoration mode</a><dd><var>navigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=scroll-to-fragid:nav-active-history-entry-3>active session history
     entry</a>'s <a href=#she-scroll-restoration-mode id=scroll-to-fragid:she-scroll-restoration-mode-2>scroll restoration mode</a></dl>

    <div class=note>
     <p>For navigations performed with <code id=scroll-to-fragid:dom-navigation-navigate><a href=nav-history-apis.html#dom-navigation-navigate>navigation.navigate()</a></code>, the value provided by the <code id=scroll-to-fragid:dom-navigationnavigateoptions-state><a href=nav-history-apis.html#dom-navigationnavigateoptions-state>state</a></code> option is used for the new <a href=#she-navigation-api-state id=scroll-to-fragid:she-navigation-api-state-3>navigation API state</a>. (This will set it to the
     serialization of undefined, if no value is provided for that option.) For other fragment
     navigations, including user-initiated ones, the <a href=#she-navigation-api-state id=scroll-to-fragid:she-navigation-api-state-4>navigation API state</a> is carried over from the previous
     entry.</p>

     <p>The <a href=#she-classic-history-api-state id=scroll-to-fragid:she-classic-history-api-state>classic history API state</a> is never
     carried over.</p>
    </div>
   <li><p>Let <var>entryToReplace</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=scroll-to-fragid:nav-active-history-entry-4>active session history entry</a> if
   <var>historyHandling</var> is "<code id=scroll-to-fragid:navigationhistorybehavior-replace><a href=#navigationhistorybehavior-replace>replace</a></code>",
   otherwise null.<li><p>Let <var>history</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-document id=scroll-to-fragid:nav-document>active
   document</a>'s <a href=nav-history-apis.html#doc-history id=scroll-to-fragid:doc-history>history object</a>.<li><p>Let <var>scriptHistoryIndex</var> be <var>history</var>'s <a href=nav-history-apis.html#concept-history-index id=scroll-to-fragid:concept-history-index>index</a>.<li><p>Let <var>scriptHistoryLength</var> be <var>history</var>'s <a href=nav-history-apis.html#concept-history-length id=scroll-to-fragid:concept-history-length>length</a>.<li>
    <p>If <var>historyHandling</var> is "<code id=scroll-to-fragid:navigationhistorybehavior-push><a href=#navigationhistorybehavior-push>push</a></code>",
    then:</p>

    <ol><li><p>Set <var>history</var>'s <a href=nav-history-apis.html#concept-history-state id=scroll-to-fragid:concept-history-state>state</a> to
     null.<li><p>Increment <var>scriptHistoryIndex</var>.<li><p>Set <var>scriptHistoryLength</var> to <var>scriptHistoryIndex</var> + 1.</ol>
   <li><p>Set <var>navigable</var>'s <a href=document-sequences.html#nav-document id=scroll-to-fragid:nav-document-2>active document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-url id="scroll-to-fragid:the-document's-address" data-x-internal="the-document's-address">URL</a> to <var>url</var>.<li><p>Set <var>navigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=scroll-to-fragid:nav-active-history-entry-5>active session history
   entry</a> to <var>historyEntry</var>.<li>
    <p><a href=#update-document-for-history-step-application id=scroll-to-fragid:update-document-for-history-step-application>Update document for history step application</a> given <var>navigable</var>'s
    <a href=document-sequences.html#nav-document id=scroll-to-fragid:nav-document-3>active document</a>, <var>historyEntry</var>, true,
    <var>scriptHistoryIndex</var>, <var>scriptHistoryLength</var>, and
    <var>historyHandling</var>.</p>

    <p class=note>This algorithm will be called twice as a result of a single fragment
    navigation: once synchronously, where best-guess values <var>scriptHistoryIndex</var> and
    <var>scriptHistoryLength</var> are set, <code id=scroll-to-fragid:dom-history-state><a href=nav-history-apis.html#dom-history-state>history.state</a></code>
    is nulled out, and various events are fired; and once asynchronously, where the final values for
    index and length are set, <code id=scroll-to-fragid:dom-history-state-2><a href=nav-history-apis.html#dom-history-state>history.state</a></code> remains
    untouched, and no events are fired.</p>
   <li>
    <p><a href=#scroll-to-the-fragment-identifier id=scroll-to-fragid:scroll-to-the-fragment-identifier>Scroll to the fragment</a> given <var>navigable</var>'s <a href=document-sequences.html#nav-document id=scroll-to-fragid:nav-document-4>active document</a>.</p>

    <p class=note>If the scrolling fails because the <code id=scroll-to-fragid:document><a href=dom.html#document>Document</a></code> is new and the
    relevant <a href=https://dom.spec.whatwg.org/#concept-id id=scroll-to-fragid:concept-id data-x-internal=concept-id>ID</a> has not yet been parsed, then the second
    asynchronous call to <a href=#update-document-for-history-step-application id=scroll-to-fragid:update-document-for-history-step-application-2>update document for history step application</a> will take
    care of scrolling.</p>
   <li><p>Let <var>traversable</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-traversable id=scroll-to-fragid:nav-traversable>traversable navigable</a>.<li>
    <p><a href=#tn-append-session-history-sync-nav-steps id=scroll-to-fragid:tn-append-session-history-sync-nav-steps>Append the following session history
    synchronous navigation steps</a> involving <var>navigable</var> to
    <var>traversable</var>:</p>

    <ol><li><p><a href=#finalize-a-same-document-navigation id=scroll-to-fragid:finalize-a-same-document-navigation>Finalize a same-document navigation</a> given <var>traversable</var>,
     <var>navigable</var>, <var>historyEntry</var>, <var>entryToReplace</var>,
     <var>historyHandling</var>, and <var>userInvolvement</var>.<li><p>Invoke <a id=scroll-to-fragid:webdriver-bidi-fragment-navigated href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-fragment-navigated data-x-internal=webdriver-bidi-fragment-navigated>WebDriver BiDi fragment navigated</a> with <var>navigable</var> and a
     new <a id=scroll-to-fragid:webdriver-bidi-navigation-status href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-navigation-status data-x-internal=webdriver-bidi-navigation-status>WebDriver BiDi navigation status</a> whose <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-id id=scroll-to-fragid:navigation-status-id data-x-internal=navigation-status-id>id</a> is <var>navigationId</var>, <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-url id=scroll-to-fragid:navigation-status-url data-x-internal=navigation-status-url>url</a> is <var>url</var>, and <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-status id=scroll-to-fragid:navigation-status-status data-x-internal=navigation-status-status>status</a> is "<code id=scroll-to-fragid:navigation-status-complete><a data-x-internal=navigation-status-complete href=https://w3c.github.io/webdriver-bidi/#navigation-status-complete>complete</a></code>".</ol>
   </ol>

  <p>To <dfn id=finalize-a-same-document-navigation>finalize a same-document navigation</dfn> given a <a id=scroll-to-fragid:traversable-navigable href=document-sequences.html#traversable-navigable>traversable navigable</a>
  <var>traversable</var>, a <a id=scroll-to-fragid:navigable-2 href=document-sequences.html#navigable>navigable</a> <var>targetNavigable</var>, a <a href=#session-history-entry id=scroll-to-fragid:session-history-entry-2>session
  history entry</a> <var>targetEntry</var>, a <a href=#session-history-entry id=scroll-to-fragid:session-history-entry-3>session history entry</a>-or-null
  <var>entryToReplace</var>, a <a href=#history-handling-behavior id=scroll-to-fragid:history-handling-behavior-2>history handling behavior</a> <var>historyHandling</var>,
  and a <a href=#user-navigation-involvement id=scroll-to-fragid:user-navigation-involvement-2>user navigation involvement</a> <var>userInvolvement</var>:</p>

  <p class=note>This is used by both <a href=#navigate-fragid id=scroll-to-fragid:navigate-fragid>fragment navigations</a>
  and by the <a href=#url-and-history-update-steps id=scroll-to-fragid:url-and-history-update-steps>URL and history update steps</a>, which are the only synchronous updates to
  session history. By virtue of being synchronous, those algorithms are performed outside of the
  <a id=scroll-to-fragid:top-level-traversable href=document-sequences.html#top-level-traversable>top-level traversable</a>'s <a href=document-sequences.html#tn-session-history-traversal-queue id=scroll-to-fragid:tn-session-history-traversal-queue>session
  history traversal queue</a>. This puts them out of sync with the <a id=scroll-to-fragid:top-level-traversable-2 href=document-sequences.html#top-level-traversable>top-level
  traversable</a>'s <a href=document-sequences.html#tn-current-session-history-step id=scroll-to-fragid:tn-current-session-history-step>current session history
  step</a>, so this algorithm is used to resolve conflicts due to race conditions.</p>

  <ol><li><p><a id=scroll-to-fragid:assert href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: this is running on <var>traversable</var>'s <a href=document-sequences.html#tn-session-history-traversal-queue id=scroll-to-fragid:tn-session-history-traversal-queue-2>session history traversal queue</a>.<li><p>If <var>targetNavigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=scroll-to-fragid:nav-active-history-entry-6>active session
   history entry</a> is not <var>targetEntry</var>, then return.<li><p>Let <var>targetStep</var> be null.<li><p>Let <var>targetEntries</var> be the result of <a href=#getting-session-history-entries id=scroll-to-fragid:getting-session-history-entries>getting session history
   entries</a> for <var>targetNavigable</var>.<li>
    <p>If <var>entryToReplace</var> is null, then:</p>

    <ol><li><p><a href=#clear-the-forward-session-history id=scroll-to-fragid:clear-the-forward-session-history>Clear the forward session history</a> of <var>traversable</var>.<li><p>Set <var>targetStep</var> to <var>traversable</var>'s <a href=document-sequences.html#tn-current-session-history-step id=scroll-to-fragid:tn-current-session-history-step-2>current session history step</a> + 1.<li><p>Set <var>targetEntry</var>'s <a href=#she-step id=scroll-to-fragid:she-step>step</a> to
     <var>targetStep</var>.<li><p><a href=https://infra.spec.whatwg.org/#list-append id=scroll-to-fragid:list-append data-x-internal=list-append>Append</a> <var>targetEntry</var> to
     <var>targetEntries</var>.</ol>

    <p>Otherwise:</p>

    <ol><li><p><a href=https://infra.spec.whatwg.org/#list-replace id=scroll-to-fragid:list-replace data-x-internal=list-replace>Replace</a> <var>entryToReplace</var> with
     <var>targetEntry</var> in <var>targetEntries</var>.<li><p>Set <var>targetEntry</var>'s <a href=#she-step id=scroll-to-fragid:she-step-2>step</a> to
     <var>entryToReplace</var>'s <a href=#she-step id=scroll-to-fragid:she-step-3>step</a>.<li><p>Set <var>targetStep</var> to <var>traversable</var>'s <a href=document-sequences.html#tn-current-session-history-step id=scroll-to-fragid:tn-current-session-history-step-3>current session history step</a>.</ol>
   <li>
    <p><a href=#apply-the-push/replace-history-step id=scroll-to-fragid:apply-the-push/replace-history-step>Apply the push/replace history step</a> <var>targetStep</var> to
    <var>traversable</var> given <var>historyHandling</var> and <var>userInvolvement</var>.</p>

    <p class=note>This is done even for "<code id=scroll-to-fragid:navigationhistorybehavior-replace-2><a href=#navigationhistorybehavior-replace>replace</a></code>" navigations, as it resolves race
    conditions across multiple synchronous navigations.</p>
   </ol>


  <h6 id=non-fetch-schemes-and-external-software><span class=secno>7.4.2.3.4</span> Non-fetch schemes and external software<a href=#non-fetch-schemes-and-external-software class=self-link></a></h6>

  <p>The input to <a href=#attempt-to-create-a-non-fetch-scheme-document id=non-fetch-schemes-and-external-software:attempt-to-create-a-non-fetch-scheme-document>attempt to create a non-fetch scheme document</a> is the <dfn id=non-fetch-scheme-navigation-params>non-fetch
  scheme navigation params</dfn> <a id=non-fetch-schemes-and-external-software:struct href=https://infra.spec.whatwg.org/#struct data-x-internal=struct>struct</a>. It is a lightweight version of
  <a href=#navigation-params id=non-fetch-schemes-and-external-software:navigation-params>navigation params</a> which only carries parameters relevant to the non-<a id=non-fetch-schemes-and-external-software:fetch-scheme href=https://fetch.spec.whatwg.org/#fetch-scheme data-x-internal=fetch-scheme>fetch
  scheme</a> navigation case. It has the following <a href=https://infra.spec.whatwg.org/#struct-item id=non-fetch-schemes-and-external-software:struct-item data-x-internal=struct-item>items</a>:</p>

  
  <dl><dt><dfn id=non-fetch-scheme-params-id>id</dfn><dd>null or a <a href=#navigation-id id=non-fetch-schemes-and-external-software:navigation-id>navigation ID</a><dt><dfn id=non-fetch-scheme-params-navigable>navigable</dfn><dd>the <a id=non-fetch-schemes-and-external-software:navigable href=document-sequences.html#navigable>navigable</a> experiencing the navigation<dt><dfn id=non-fetch-scheme-params-url>URL</dfn><dd>a <a id=non-fetch-schemes-and-external-software:url href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a><dt><dfn id=non-fetch-scheme-params-target-sandbox>target snapshot sandboxing flags</dfn><dd>the <a href=#target-snapshot-params id=non-fetch-schemes-and-external-software:target-snapshot-params>target snapshot params</a>'s <a href=#target-snapshot-params-sandbox id=non-fetch-schemes-and-external-software:target-snapshot-params-sandbox>sandboxing flags</a> present during navigation<dt><dfn id=non-fetch-scheme-params-source-activation>source snapshot has transient activation</dfn><dd>a copy of the <a href=#source-snapshot-params id=non-fetch-schemes-and-external-software:source-snapshot-params>source snapshot params</a>'s <a href=#source-snapshot-params-activation id=non-fetch-schemes-and-external-software:source-snapshot-params-activation>has transient activation</a> boolean present during
   activation<dt><dfn id=non-fetch-scheme-params-initiator-origin>initiator origin</dfn><dd>
    <p>an <a id=non-fetch-schemes-and-external-software:concept-origin href=browsers.html#concept-origin>origin</a> possibly for use in a user-facing prompt to confirm the invocation of
    an external software package</p>
    <p class=note>This differs slightly from a <a href=#she-document-state id=non-fetch-schemes-and-external-software:she-document-state>document
    state</a>'s <a href=#document-state-initiator-origin id=non-fetch-schemes-and-external-software:document-state-initiator-origin>initiator origin</a> in that a
    <a href=#non-fetch-scheme-navigation-params id=non-fetch-schemes-and-external-software:non-fetch-scheme-navigation-params>non-fetch scheme navigation params</a>'s <a href=#non-fetch-scheme-params-initiator-origin id=non-fetch-schemes-and-external-software:non-fetch-scheme-params-initiator-origin>initiator origin</a> follows redirects up
    to the last <a id=non-fetch-schemes-and-external-software:fetch-scheme-2 href=https://fetch.spec.whatwg.org/#fetch-scheme data-x-internal=fetch-scheme>fetch scheme</a> URL in a redirect chain that ends in a non-<a id=non-fetch-schemes-and-external-software:fetch-scheme-3 href=https://fetch.spec.whatwg.org/#fetch-scheme data-x-internal=fetch-scheme>fetch
    scheme</a> URL.</p>
   <dt><dfn id=non-fetch-scheme-params-nav-timing-type>navigation timing type</dfn><dd>a <code id=non-fetch-schemes-and-external-software:navigationtimingtype><a data-x-internal=navigationtimingtype href=https://w3c.github.io/navigation-timing/#dom-navigationtimingtype>NavigationTimingType</a></code> used for <a href=https://w3c.github.io/navigation-timing/#dfn-create-the-navigation-timing-entry id=non-fetch-schemes-and-external-software:create-the-navigation-timing-entry data-x-internal=create-the-navigation-timing-entry>creating the navigation timing entry</a> for the new <code id=non-fetch-schemes-and-external-software:document><a href=dom.html#document>Document</a></code> (if one is
   created)<dt><dfn id=non-fetch-scheme-params-user-involvement>user involvement</dfn><dd>a <a href=#user-navigation-involvement id=non-fetch-schemes-and-external-software:user-navigation-involvement>user navigation involvement</a> used when <a href=browsers.html#obtain-browsing-context-navigation id=non-fetch-schemes-and-external-software:obtain-browsing-context-navigation>obtaining a browsing context</a> for the new
   <code id=non-fetch-schemes-and-external-software:document-2><a href=dom.html#document>Document</a></code> (if one is created)</dl>

  <p id=process-a-navigate-url-scheme>To <dfn id=attempt-to-create-a-non-fetch-scheme-document>attempt to create a non-fetch scheme document</dfn>,
  given a <a href=#non-fetch-scheme-navigation-params id=non-fetch-schemes-and-external-software:non-fetch-scheme-navigation-params-2>non-fetch scheme navigation params</a> <var>navigationParams</var>:</p>

  <ol><li>Let <var>url</var> be <var>navigationParams</var>'s <a href=#non-fetch-scheme-params-url id=non-fetch-schemes-and-external-software:non-fetch-scheme-params-url>URL</a>.<li>Let <var>navigable</var> be <var>navigationParams</var>'s <a href=#non-fetch-scheme-params-navigable id=non-fetch-schemes-and-external-software:non-fetch-scheme-params-navigable>navigable</a>.<li>
    <p>If <var>url</var> is to be handled using a mechanism that does not affect
    <var>navigable</var>, e.g., because <var>url</var>'s <a href=https://url.spec.whatwg.org/#concept-url-scheme id=non-fetch-schemes-and-external-software:concept-url-scheme data-x-internal=concept-url-scheme>scheme</a> is handled externally, then:</p>

    <ol><li><p><a href=#hand-off-to-external-software id=non-fetch-schemes-and-external-software:hand-off-to-external-software>Hand-off to external software</a> given <var>url</var>, <var>navigable</var>,
     <var>navigationParams</var>'s <a href=#non-fetch-scheme-params-target-sandbox id=non-fetch-schemes-and-external-software:non-fetch-scheme-params-target-sandbox>target
     snapshot sandboxing flags</a>, <var>navigationParams</var>'s <a href=#non-fetch-scheme-params-source-activation id=non-fetch-schemes-and-external-software:non-fetch-scheme-params-source-activation>source snapshot has transient
     activation</a>, and <var>navigationParams</var>'s <a href=#non-fetch-scheme-params-initiator-origin id=non-fetch-schemes-and-external-software:non-fetch-scheme-params-initiator-origin-2>initiator origin</a>.<li><p>Return null.</ol>
   <li>
    <p>Handle <var>url</var> by displaying some sort of inline content, e.g., an error message
    because the specified scheme is not one of the supported protocols, or an inline prompt to allow
    the user to select <a href=system-state.html#dom-navigator-registerprotocolhandler id=non-fetch-schemes-and-external-software:dom-navigator-registerprotocolhandler>a registered
    handler</a> for the given scheme. Return the result of <a href=document-lifecycle.html#read-ua-inline id=non-fetch-schemes-and-external-software:read-ua-inline>displaying the inline content</a> given <var>navigable</var>,
    <var>navigationParams</var>'s <a href=#non-fetch-scheme-params-id id=non-fetch-schemes-and-external-software:non-fetch-scheme-params-id>id</a>,
    <var>navigationParams</var>'s <a href=#non-fetch-scheme-params-nav-timing-type id=non-fetch-schemes-and-external-software:non-fetch-scheme-params-nav-timing-type>navigation
    timing type</a>, and <var>navigationParams</var>'s <a href=#non-fetch-scheme-params-user-involvement id=non-fetch-schemes-and-external-software:non-fetch-scheme-params-user-involvement>user involvement</a>.</p>

    <p class=note>In the case of a registered handler being used, <a href=#navigate id=non-fetch-schemes-and-external-software:navigate>navigate</a> will be
    invoked with a new URL.</p>
   </ol>

  <p>To <dfn id=hand-off-to-external-software>hand-off to external software</dfn> given a <a id=non-fetch-schemes-and-external-software:url-2 href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> or <a href=https://fetch.spec.whatwg.org/#concept-response id=non-fetch-schemes-and-external-software:concept-response data-x-internal=concept-response>response</a> <var>resource</var>, a <a id=non-fetch-schemes-and-external-software:navigable-2 href=document-sequences.html#navigable>navigable</a>
  <var>navigable</var>, a <a id=non-fetch-schemes-and-external-software:sandboxing-flag-set href=browsers.html#sandboxing-flag-set>sandboxing flag set</a> <var>sandboxFlags</var>, a boolean
  <var>hasTransientActivation</var>, and an <a id=non-fetch-schemes-and-external-software:concept-origin-2 href=browsers.html#concept-origin>origin</a> <var>initiatorOrigin</var>, user
  agents should:</p>

  <ol><li>
    <p>If all of the following are true:</p>

    <ul><li><p><var>navigable</var> is not a <a id=non-fetch-schemes-and-external-software:top-level-traversable href=document-sequences.html#top-level-traversable>top-level traversable</a>;<li><p><var>sandboxFlags</var> has its <a id=non-fetch-schemes-and-external-software:sandboxed-custom-protocols-navigation-browsing-context-flag href=browsers.html#sandboxed-custom-protocols-navigation-browsing-context-flag>sandboxed custom protocols navigation browsing
     context flag</a> set; and<li><p><var>sandboxFlags</var> has its <a id=non-fetch-schemes-and-external-software:sandboxed-top-level-navigation-with-user-activation-browsing-context-flag href=browsers.html#sandboxed-top-level-navigation-with-user-activation-browsing-context-flag>sandboxed top-level navigation with user
     activation browsing context flag</a> set, or <var>hasTransientActivation</var> is
     false,</ul>

    <p>then return without invoking the external software package.</p>

    <p class=note>Navigation inside an iframe toward external software can be seen by users as a
    new popup or a new top-level navigation. That's why its is allowed in sandboxed
    <code id=non-fetch-schemes-and-external-software:the-iframe-element><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code> only when one of <code id=non-fetch-schemes-and-external-software:attr-iframe-sandbox-allow-popups><a href=browsers.html#attr-iframe-sandbox-allow-popups>allow-popups</a></code>, <code id=non-fetch-schemes-and-external-software:attr-iframe-sandbox-allow-top-navigation><a href=browsers.html#attr-iframe-sandbox-allow-top-navigation>allow-top-navigation</a></code>, <code id=non-fetch-schemes-and-external-software:attr-iframe-sandbox-allow-top-navigation-by-user-activation><a href=browsers.html#attr-iframe-sandbox-allow-top-navigation-by-user-activation>allow-top-navigation-by-user-activation</a></code>,
    or <code id=non-fetch-schemes-and-external-software:attr-iframe-sandbox-allow-top-navigation-to-custom-protocols><a href=browsers.html#attr-iframe-sandbox-allow-top-navigation-to-custom-protocols>allow-top-navigation-to-custom-protocols</a></code>
    is specified.</p>
   <li>
    <p>Perform the appropriate handoff of <var>resource</var> while attempting to mitigate the risk
    that this is an attempt to exploit the target software. For example, user agents could prompt
    the user to confirm that <var>initiatorOrigin</var> is to be allowed to invoke the external
    software in question. In particular, if <var>hasTransientActivation</var> is false, then the
    user agent should not invoke the external software package without prior user confirmation.</p>

    <p class=example>For example, there could be a vulnerability in the target software's URL
    handler which a hostile page would attempt to exploit by tricking a user into clicking a
    link.</p>
   </ol>


  <h5 id=preventing-navigation><span class=secno>7.4.2.4</span> Preventing navigation<a href=#preventing-navigation class=self-link></a></h5>

  <p>A couple of scenarios can intervene early in the navigation process and put the whole thing to
  a halt. This can be especially exciting when multiple <a href=document-sequences.html#navigable id=preventing-navigation:navigable>navigables</a>
  are navigating at the same time, due to a session history traversal.</p>

  <p>A <a id=preventing-navigation:navigable-2 href=document-sequences.html#navigable>navigable</a> <var>source</var> is <dfn id=allowed-to-navigate>allowed by
  sandboxing to navigate</dfn> a second <a id=preventing-navigation:navigable-3 href=document-sequences.html#navigable>navigable</a> <var>target</var>, given a
  <a href=#source-snapshot-params id=preventing-navigation:source-snapshot-params>source snapshot params</a> <var>sourceSnapshotParams</var>, if the following steps
  return true:</p>

  <ol><li><p>If <var>source</var> is <var>target</var>, then return true.<li><p>If <var>source</var> is an ancestor of <var>target</var>, then return true.<li>
    <p>If <var>target</var> is an ancestor of <var>source</var>, then:</p>

    <ol><li><p>If <var>target</var> is not a <a id=preventing-navigation:top-level-traversable href=document-sequences.html#top-level-traversable>top-level traversable</a>, then return
     true.<li><p>If <var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-activation id=preventing-navigation:source-snapshot-params-activation>has transient activation</a> is true, and
     <var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-sandbox id=preventing-navigation:source-snapshot-params-sandbox>sandboxing
     flags</a>'s <a id=preventing-navigation:sandboxed-top-level-navigation-with-user-activation-browsing-context-flag href=browsers.html#sandboxed-top-level-navigation-with-user-activation-browsing-context-flag>sandboxed top-level navigation with user activation browsing context
     flag</a> is set, then return false.<li><p>If <var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-activation id=preventing-navigation:source-snapshot-params-activation-2>has transient activation</a> is false, and
     <var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-sandbox id=preventing-navigation:source-snapshot-params-sandbox-2>sandboxing
     flags</a>'s <a id=preventing-navigation:sandboxed-top-level-navigation-without-user-activation-browsing-context-flag href=browsers.html#sandboxed-top-level-navigation-without-user-activation-browsing-context-flag>sandboxed top-level navigation without user activation browsing context
     flag</a> is set, then return false.<li><p>Return true.</ol>
   <li>
    <p>If <var>target</var> is a <a id=preventing-navigation:top-level-traversable-2 href=document-sequences.html#top-level-traversable>top-level traversable</a>:</p>

    <ol><li><p>If <var>source</var> is the <a id=preventing-navigation:one-permitted-sandboxed-navigator href=browsers.html#one-permitted-sandboxed-navigator>one permitted sandboxed navigator</a> of
     <var>target</var>, then return true.<li><p>If <var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-sandbox id=preventing-navigation:source-snapshot-params-sandbox-3>sandboxing flags</a>'s <a id=preventing-navigation:sandboxed-navigation-browsing-context-flag href=browsers.html#sandboxed-navigation-browsing-context-flag>sandboxed navigation
     browsing context flag</a> is set, then return false.<li><p>Return true.</ol>
   <li><p>If <var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-sandbox id=preventing-navigation:source-snapshot-params-sandbox-4>sandboxing flags</a>'s <a id=preventing-navigation:sandboxed-navigation-browsing-context-flag-2 href=browsers.html#sandboxed-navigation-browsing-context-flag>sandboxed navigation
   browsing context flag</a> is set, then return false.<li><p>Return true.</ol>

  <p id=prompt-to-unload-a-document><span id=prompt-to-unload></span><span id=checking-if-unloading-is-user-canceled></span>To <dfn id=checking-if-unloading-is-canceled>check if unloading is canceled</dfn> for a <a id=preventing-navigation:list href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a> of <a href=document-sequences.html#navigable id=preventing-navigation:navigable-4>navigables</a> <var>navigablesThatNeedBeforeUnload</var>, given an optional
  <a id=preventing-navigation:traversable-navigable href=document-sequences.html#traversable-navigable>traversable navigable</a> <var>traversable</var>, an optional integer
  <var>targetStep</var>, and an optional <a href=#user-navigation-involvement id=preventing-navigation:user-navigation-involvement>user navigation involvement</a>
  <var>userInvolvementForNavigateEvent</var>, run these steps. They return "<code>canceled-by-beforeunload</code>", "<code>canceled-by-navigate</code>", or
  "<code>continue</code>".</p>

  <ol><li><p>Let <var>documentsToFireBeforeunload</var> be the <a href=document-sequences.html#nav-document id=preventing-navigation:nav-document>active
   document</a> of each <a href=https://infra.spec.whatwg.org/#list-item id=preventing-navigation:list-item data-x-internal=list-item>item</a> in
   <var>navigablesThatNeedBeforeUnload</var>.<li><p>Let <var>unloadPromptShown</var> be false.<li><p>Let <var>finalStatus</var> be "<code>continue</code>".<li>
    <p>If <var>traversable</var> was given, then:</p>

    <ol><li><p><a id=preventing-navigation:assert href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>targetStep</var> and
     <var>userInvolvementForNavigateEvent</var> were given.<li><p>Let <var>targetEntry</var> be the result of <a href=#getting-the-target-history-entry id=preventing-navigation:getting-the-target-history-entry>getting the target history
     entry</a> given <var>traversable</var> and <var>targetStep</var>.<li>
      <p>If <var>targetEntry</var> is not <var>traversable</var>'s <a href=document-sequences.html#nav-current-history-entry id=preventing-navigation:nav-current-history-entry>current session history entry</a>, and
      <var>targetEntry</var>'s <a href=#she-document-state id=preventing-navigation:she-document-state>document state</a>'s <a href=#document-state-origin id=preventing-navigation:document-state-origin>origin</a> is the <a href=browsers.html#same-origin id=preventing-navigation:same-origin>same</a> as
      <var>traversable</var>'s <a href=document-sequences.html#nav-current-history-entry id=preventing-navigation:nav-current-history-entry-2>current session history
      entry</a>'s <a href=#she-document-state id=preventing-navigation:she-document-state-2>document state</a>'s <a href=#document-state-origin id=preventing-navigation:document-state-origin-2>origin</a>, then:</p>

      <div class=note>
       <p>In this case, we're going to fire the <code id=preventing-navigation:event-navigate><a href=indices.html#event-navigate>navigate</a></code> event
       for <var>traversable</var> here. Because <a href=nav-history-apis.html#navigate-event-traverse-can-be-canceled>under some circumstances</a> it might be
       canceled, we need to do this separately from <a href=#descendant-navigable-traversal-navigate-events>other traversal <code>navigate</code> events</a>, which happen later.</p>

       <p>Additionally, because we want <code id=preventing-navigation:event-beforeunload><a href=indices.html#event-beforeunload>beforeunload</a></code> events
       to fire before <code id=preventing-navigation:event-navigate-2><a href=indices.html#event-navigate>navigate</a></code> events, this means we need to
       fire <code id=preventing-navigation:event-beforeunload-2><a href=indices.html#event-beforeunload>beforeunload</a></code> for <var>traversable</var> here
       (if applicable), instead of doing it as part of the below loop over
       <var>documentsToFireBeforeunload</var>.</p>
      </div>

      <ol><li><p>Let <var>eventsFired</var> be false.<li><p>Let <var>needsBeforeunload</var> be true if <var>navigablesThatNeedBeforeUnload</var>
       <a href=https://infra.spec.whatwg.org/#list-contain id=preventing-navigation:list-contains data-x-internal=list-contains>contains</a> <var>traversable</var>; otherwise
       false.<li><p>If <var>needsBeforeunload</var> is true, then <a href=https://infra.spec.whatwg.org/#list-remove id=preventing-navigation:list-remove data-x-internal=list-remove>remove</a>
       <var>traversable</var>'s <a href=document-sequences.html#nav-document id=preventing-navigation:nav-document-2>active document</a> from
       <var>documentsToFireBeforeunload</var>.<li>
        <p><a id=preventing-navigation:queue-a-global-task href=webappapis.html#queue-a-global-task>Queue a global task</a> on the <a id=preventing-navigation:navigation-and-traversal-task-source href=webappapis.html#navigation-and-traversal-task-source>navigation and traversal task source</a>
        given <var>traversable</var>'s <a href=document-sequences.html#nav-window id=preventing-navigation:nav-window>active window</a> to perform the
        following steps:</p>

        <ol><li>
          <p>If <var>needsBeforeunload</var> is true, then:</p>

          <ol><li><p>Let (<var>unloadPromptShownForThisDocument</var>,
           <var>unloadPromptCanceledByThisDocument</var>) be the result of running the <a href=#steps-to-fire-beforeunload id=preventing-navigation:steps-to-fire-beforeunload>steps
           to fire <code>beforeunload</code></a> given
           <var>traversable</var>'s <a href=document-sequences.html#nav-document id=preventing-navigation:nav-document-3>active document</a> and
           false.<li><p>If <var>unloadPromptShownForThisDocument</var> is true, then set
           <var>unloadPromptShown</var> to true.<li><p>If <var>unloadPromptCanceledByThisDocument</var> is true, then set
           <var>finalStatus</var> to "<code>canceled-by-beforeunload</code>".</ol>
         <li><p>If <var>finalStatus</var> is "<code>canceled-by-beforeunload</code>", then
         abort these steps.<li><p>Let <var>navigation</var> be <var>traversable</var>'s <a href=document-sequences.html#nav-window id=preventing-navigation:nav-window-2>active window</a>'s <a href=nav-history-apis.html#window-navigation-api id=preventing-navigation:window-navigation-api>navigation
         API</a>.<li><p>Let <var>navigateEventResult</var> be the result of <a href=nav-history-apis.html#fire-a-traverse-navigate-event id=preventing-navigation:fire-a-traverse-navigate-event>firing a traverse <code>navigate</code>
         event</a> at <var>navigation</var> given <var>targetEntry</var> and
         <var>userInvolvementForNavigateEvent</var>.<li><p>If <var>navigateEventResult</var> is false, then set <var>finalStatus</var> to
         "<code>canceled-by-navigate</code>".<li><p>Set <var>eventsFired</var> to true.</ol>
       <li><p>Wait until <var>eventsFired</var> is true.<li><p>If <var>finalStatus</var> is not "<code>continue</code>", then return
       <var>finalStatus</var>.</ol>
     </ol>
   <li><p>Let <var>totalTasks</var> be the <a href=https://infra.spec.whatwg.org/#list-size id=preventing-navigation:list-size data-x-internal=list-size>size</a> of
   <var>documentsToFireBeforeunload</var>.<li><p>Let <var>completedTasks</var> be 0.<li>
    <p><a href=https://infra.spec.whatwg.org/#list-iterate id=preventing-navigation:list-iterate data-x-internal=list-iterate>For each</a> <var>document</var> of <var>documentsToFireBeforeunload</var>,
    <a id=preventing-navigation:queue-a-global-task-2 href=webappapis.html#queue-a-global-task>queue a global task</a> on the <a id=preventing-navigation:navigation-and-traversal-task-source-2 href=webappapis.html#navigation-and-traversal-task-source>navigation and traversal task source</a> given
    <var>document</var>'s <a id=preventing-navigation:concept-relevant-global href=webappapis.html#concept-relevant-global>relevant global object</a> to run the steps:</p>

    <ol><li><p>Let (<var>unloadPromptShownForThisDocument</var>,
     <var>unloadPromptCanceledByThisDocument</var>) be the result of running the <a href=#steps-to-fire-beforeunload id=preventing-navigation:steps-to-fire-beforeunload-2>steps to fire
     <code>beforeunload</code></a> given <var>document</var> and
     <var>unloadPromptShown</var>.<li><p>If <var>unloadPromptShownForThisDocument</var> is true, then set
     <var>unloadPromptShown</var> to true.<li><p>If <var>unloadPromptCanceledByThisDocument</var> is true, then set
     <var>finalStatus</var> to "<code>canceled-by-beforeunload</code>".<li><p>Increment <var>completedTasks</var>.</ol>
   <li><p>Wait for <var>completedTasks</var> to be <var>totalTasks</var>.<li><p>Return <var>finalStatus</var>.</ol>

  <p>The <dfn id=steps-to-fire-beforeunload>steps to fire <code>beforeunload</code></dfn> given a
  <code id=preventing-navigation:document><a href=dom.html#document>Document</a></code> <var>document</var> and a boolean <var>unloadPromptShown</var> are:</p>

  <ol><li><p>Let <var>unloadPromptCanceled</var> be false.<li><p>Increase the <var>document</var>'s <a id=preventing-navigation:unload-counter href=document-lifecycle.html#unload-counter>unload counter</a> by 1.<li><p>Increase <var>document</var>'s <a id=preventing-navigation:relevant-agent href=webappapis.html#relevant-agent>relevant agent</a>'s <a href=webappapis.html#concept-agent-event-loop id=preventing-navigation:concept-agent-event-loop>event loop</a>'s <a id=preventing-navigation:termination-nesting-level href=document-lifecycle.html#termination-nesting-level>termination nesting level</a> by
   1.<li><p>Let <var>eventFiringResult</var> be the result of <a href=https://dom.spec.whatwg.org/#concept-event-fire id=preventing-navigation:concept-event-fire data-x-internal=concept-event-fire>firing
   an event</a> named <code id=preventing-navigation:event-beforeunload-3><a href=indices.html#event-beforeunload>beforeunload</a></code> at
   <var>document</var>'s <a id=preventing-navigation:concept-relevant-global-2 href=webappapis.html#concept-relevant-global>relevant global object</a>, using <code id=preventing-navigation:beforeunloadevent><a href=nav-history-apis.html#beforeunloadevent>BeforeUnloadEvent</a></code>,
   with the <code id=preventing-navigation:dom-event-cancelable><a data-x-internal=dom-event-cancelable href=https://dom.spec.whatwg.org/#dom-event-cancelable>cancelable</a></code> attribute initialized to
   true.<li><p>Decrease <var>document</var>'s <a id=preventing-navigation:relevant-agent-2 href=webappapis.html#relevant-agent>relevant agent</a>'s <a href=webappapis.html#concept-agent-event-loop id=preventing-navigation:concept-agent-event-loop-2>event loop</a>'s <a id=preventing-navigation:termination-nesting-level-2 href=document-lifecycle.html#termination-nesting-level>termination nesting level</a> by
   1.<li>
    <p>If all of the following are true:</p>

    <ul><li><p><var>unloadPromptShown</var> is false;<li><p><var>document</var>'s <a id=preventing-navigation:active-sandboxing-flag-set href=browsers.html#active-sandboxing-flag-set>active sandboxing flag set</a> does not have its
     <a id=preventing-navigation:sandboxed-modals-flag href=browsers.html#sandboxed-modals-flag>sandboxed modals flag</a> set;<li><p><var>document</var>'s <a id=preventing-navigation:concept-relevant-global-3 href=webappapis.html#concept-relevant-global>relevant global object</a> has <a id=preventing-navigation:sticky-activation href=interaction.html#sticky-activation>sticky
     activation</a>;<li><p><var>eventFiringResult</var> is false, or the <code id=preventing-navigation:dom-beforeunloadevent-returnvalue><a href=nav-history-apis.html#dom-beforeunloadevent-returnvalue>returnValue</a></code> attribute of <var>event</var> is
     not the empty string; and<li><p>showing an unload prompt is unlikely to be annoying, deceptive, or pointless,</ul>

    <p>then:</p>

    <ol><li><p>Set <var>unloadPromptShown</var> to true.<li><p>Let <var>userPromptHandler</var> be the result of <a id=preventing-navigation:webdriver-bidi-user-prompt-opened href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-user-prompt-opened data-x-internal=webdriver-bidi-user-prompt-opened>WebDriver BiDi user prompt
     opened</a> with <var>document</var>'s <a id=preventing-navigation:concept-relevant-global-4 href=webappapis.html#concept-relevant-global>relevant global object</a>,
     "<code>beforeunload</code>", and "".<li><p>If <var>userPromptHandler</var> is "<code>dismiss</code>", then set
     <var>unloadPromptCanceled</var> to true.<li>
      <p>If <var>userPromptHandler</var> is "<code>none</code>", then:</p>

      <ol><li>
        <p>Ask the user to confirm that they wish to unload the document, and <a id=preventing-navigation:pause href=webappapis.html#pause>pause</a>
        while waiting for the user's response.</p>

        <p class=note>The message shown to the user is not customizable, but instead determined by
        the user agent. In particular, the actual value of the <code id=preventing-navigation:dom-beforeunloadevent-returnvalue-2><a href=nav-history-apis.html#dom-beforeunloadevent-returnvalue>returnValue</a></code> attribute is ignored.</p>
       <li><p>If the user did not confirm the page navigation, then set
       <var>unloadPromptCanceled</var> to true.</ol>

     <li><p>Invoke <a id=preventing-navigation:webdriver-bidi-user-prompt-closed href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-user-prompt-closed data-x-internal=webdriver-bidi-user-prompt-closed>WebDriver BiDi user prompt closed</a> with <var>document</var>'s
     <a id=preventing-navigation:concept-relevant-global-5 href=webappapis.html#concept-relevant-global>relevant global object</a>, "<code>beforeunload</code>", and true
     if <var>unloadPromptCanceled</var> is false or false otherwise.</ol>
   <li><p>Decrease <var>document</var>'s <a id=preventing-navigation:unload-counter-2 href=document-lifecycle.html#unload-counter>unload counter</a> by 1.<li><p>Return (<var>unloadPromptShown</var>, <var>unloadPromptCanceled</var>).</ol>


  <h5 id=aborting-navigation><span class=secno>7.4.2.5</span> Aborting navigation<a href=#aborting-navigation class=self-link></a></h5>

  <p id=concept-navigate-mature>Each <a id=aborting-navigation:navigable href=document-sequences.html#navigable>navigable</a> has an <dfn id=ongoing-navigation>ongoing navigation</dfn>,
  which is a <a href=#navigation-id id=aborting-navigation:navigation-id>navigation ID</a>, "<code>traversal</code>", or null, initially
  null. It is used to track navigation aborting and to prevent any navigations from taking place
  during <a href=#apply-the-traverse-history-step id=aborting-navigation:apply-the-traverse-history-step>traversal</a>.</p>

  <p>To <dfn id=set-the-ongoing-navigation>set the ongoing navigation</dfn> for a <a id=aborting-navigation:navigable-2 href=document-sequences.html#navigable>navigable</a> <var>navigable</var> to
  <var>newValue</var>:</p>

  <ol><li><p>If <var>navigable</var>'s <a href=#ongoing-navigation id=aborting-navigation:ongoing-navigation>ongoing navigation</a> is equal to <var>newValue</var>,
   then return.<li><p><a id=aborting-navigation:inform-the-navigation-api-about-aborting-navigation href=nav-history-apis.html#inform-the-navigation-api-about-aborting-navigation>Inform the navigation API about aborting navigation</a> given
   <var>navigable</var>.<li><p>Set <var>navigable</var>'s <a href=#ongoing-navigation id=aborting-navigation:ongoing-navigation-2>ongoing navigation</a> to
   <var>newValue</var>.</ol>


  <h4 id=reloading-and-traversing><span class=secno>7.4.3</span> Reloading and traversing<a href=#reloading-and-traversing class=self-link></a></h4>

  <p>To <dfn id=reload>reload</dfn> a <a id=reloading-and-traversing:navigable href=document-sequences.html#navigable>navigable</a> <var>navigable</var> given an optional
  <a href=#serialized-state id=reloading-and-traversing:serialized-state>serialized state</a>-or-null <dfn id=reload-navigation-api-state><var>navigationAPIState</var></dfn> (default null) and an
  optional <a href=#user-navigation-involvement id=reloading-and-traversing:user-navigation-involvement>user navigation involvement</a> <dfn id=reload-user-involvement><var>userInvolvement</var></dfn> (default "<code id=reloading-and-traversing:uni-none><a href=#uni-none>none</a></code>"):</p>

  <ol><li>
    <p>If <var>userInvolvement</var> is not "<code id=reloading-and-traversing:uni-browser-ui><a href=#uni-browser-ui>browser UI</a></code>",
    then:</p>

    <ol><li><p>Let <var>navigation</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-window id=reloading-and-traversing:nav-window>active
     window</a>'s <a href=nav-history-apis.html#window-navigation-api id=reloading-and-traversing:window-navigation-api>navigation API</a>.<li><p>Let <var>destinationNavigationAPIState</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=reloading-and-traversing:nav-active-history-entry>active session history entry</a>'s <a href=#she-navigation-api-state id=reloading-and-traversing:she-navigation-api-state>navigation API state</a>.<li><p>If <var>navigationAPIState</var> is not null, then set
     <var>destinationNavigationAPIState</var> to <var>navigationAPIState</var>.<li><p>Let <var>continue</var> be the result of <a href=nav-history-apis.html#fire-a-push/replace/reload-navigate-event id=reloading-and-traversing:fire-a-push/replace/reload-navigate-event>firing a push/replace/reload <code>navigate</code>
     event</a> at <var>navigation</var> with <i id=reloading-and-traversing:fire-navigate-prr-navigationtype><a href=nav-history-apis.html#fire-navigate-prr-navigationtype>navigationType</a></i> set to "<code id=reloading-and-traversing:dom-navigationtype-reload><a href=nav-history-apis.html#dom-navigationtype-reload>reload</a></code>", <i id=reloading-and-traversing:fire-navigate-prr-issamedocument><a href=nav-history-apis.html#fire-navigate-prr-issamedocument>isSameDocument</a></i> set to false, <i id=reloading-and-traversing:fire-navigate-prr-userinvolvement><a href=nav-history-apis.html#fire-navigate-prr-userinvolvement>userInvolvement</a></i> set to
     <var>userInvolvement</var>, <i id=reloading-and-traversing:fire-navigate-prr-destinationurl><a href=nav-history-apis.html#fire-navigate-prr-destinationurl>destinationURL</a></i>
     set to <var>navigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=reloading-and-traversing:nav-active-history-entry-2>active session history
     entry</a>'s <a href=#she-url id=reloading-and-traversing:she-url>URL</a>, and <i id=reloading-and-traversing:fire-navigate-prr-navigationapistate><a href=nav-history-apis.html#fire-navigate-prr-navigationapistate>navigationAPIState</a></i> set to
     <var>destinationNavigationAPIState</var>.<li><p>If <var>continue</var> is false, then return.</ol>
   <li><p>Set <var>navigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=reloading-and-traversing:nav-active-history-entry-3>active session history
   entry</a>'s <a href=#she-document-state id=reloading-and-traversing:she-document-state>document state</a>'s <a href=#document-state-reload-pending id=reloading-and-traversing:document-state-reload-pending>reload pending</a> to true.<li><p>Let <var>traversable</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-traversable id=reloading-and-traversing:nav-traversable>traversable navigable</a>.<li>
    <p><a href=#tn-append-session-history-traversal-steps id=reloading-and-traversing:tn-append-session-history-traversal-steps>Append the following session
    history traversal steps</a> to <var>traversable</var>:</p>

    <ol><li><p><a href=#apply-the-reload-history-step id=reloading-and-traversing:apply-the-reload-history-step>Apply the reload history step</a> to <var>traversable</var> given
     <var>userInvolvement</var>.</ol>
   </ol>

  <p>To <dfn id=traverse-the-history-by-a-delta>traverse the history by a delta</dfn> given a <a id=reloading-and-traversing:traversable-navigable href=document-sequences.html#traversable-navigable>traversable navigable</a>
  <var>traversable</var>, an integer <var>delta</var>, and an optional <code id=reloading-and-traversing:document><a href=dom.html#document>Document</a></code> <dfn id=traverse-sourcedocument><var>sourceDocument</var></dfn>:</p>

  <ol><li><p>Let <var>sourceSnapshotParams</var> and <var>initiatorToCheck</var> be null.<li><p>Let <var>userInvolvement</var> be "<code id=reloading-and-traversing:uni-browser-ui-2><a href=#uni-browser-ui>browser
   UI</a></code>".<li>
    <p>If <var>sourceDocument</var> is given, then:</p>

    <ol><li><p>Set <var>sourceSnapshotParams</var> to the result of <a href=#snapshotting-source-snapshot-params id=reloading-and-traversing:snapshotting-source-snapshot-params>snapshotting source snapshot
     params</a> given <var>sourceDocument</var>.<li><p>Set <var>initiatorToCheck</var> to <var>sourceDocument</var>'s <a id=reloading-and-traversing:node-navigable href=document-sequences.html#node-navigable>node
     navigable</a>.<li><p>Set <var>userInvolvement</var> to "<code id=reloading-and-traversing:uni-none-2><a href=#uni-none>none</a></code>".</ol>
   <li>
    <p><a href=#tn-append-session-history-traversal-steps id=reloading-and-traversing:tn-append-session-history-traversal-steps-2>Append the following session
    history traversal steps</a> to <var>traversable</var>:</p>

    <ol><li><p>Let <var>allSteps</var> be the result of <a href=#getting-all-used-history-steps id=reloading-and-traversing:getting-all-used-history-steps>getting all used history steps</a>
     for <var>traversable</var>.<li><p>Let <var>currentStepIndex</var> be the index of <var>traversable</var>'s <a href=document-sequences.html#tn-current-session-history-step id=reloading-and-traversing:tn-current-session-history-step>current session history step</a> within
     <var>allSteps</var>.<li><p>Let <var>targetStepIndex</var> be <var>currentStepIndex</var> plus
     <var>delta</var>.<li><p>If <var>allSteps</var>[<var>targetStepIndex</var>] does not <a href=https://infra.spec.whatwg.org/#list-contain id=reloading-and-traversing:list-contains data-x-internal=list-contains>exist</a>, then abort these steps.<li><p><a href=#apply-the-traverse-history-step id=reloading-and-traversing:apply-the-traverse-history-step>Apply the traverse history step</a>
     <var>allSteps</var>[<var>targetStepIndex</var>] to <var>traversable</var>, given
     <var>sourceSnapshotParams</var>, <var>initiatorToCheck</var>, and
     <var>userInvolvement</var>.</ol>
   </ol>


  <h4 id=navigate-non-frag-sync><span class=secno>7.4.4</span> Non-fragment synchronous "navigations"<a href=#navigate-non-frag-sync class=self-link></a></h4>

  <p>Apart from the <a href=#navigate id=navigate-non-frag-sync:navigate>navigate</a> algorithm, <a href=#session-history-entry id=navigate-non-frag-sync:session-history-entry>session
  history entries</a> can be pushed or replaced via one more mechanism, the <a href=#url-and-history-update-steps id=navigate-non-frag-sync:url-and-history-update-steps>URL and
  history update steps</a>. The most well-known callers of these steps are the <code id=navigate-non-frag-sync:dom-history-replacestate><a href=nav-history-apis.html#dom-history-replacestate>history.replaceState()</a></code> and <code id=navigate-non-frag-sync:dom-history-pushstate><a href=nav-history-apis.html#dom-history-pushstate>history.pushState()</a></code> APIs, but various other parts of the
  standard also need to perform updates to the <a href=document-sequences.html#nav-active-history-entry id=navigate-non-frag-sync:nav-active-history-entry>active
  history entry</a>, and they use these steps to do so.</p>

  <p id=history-1>The <dfn id=url-and-history-update-steps>URL and history update steps</dfn>, given a <code id=navigate-non-frag-sync:document><a href=dom.html#document>Document</a></code>
  <var>document</var>, a <a id=navigate-non-frag-sync:url href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> <var>newURL</var>, an optional <a href=#serialized-state id=navigate-non-frag-sync:serialized-state>serialized
  state</a>-or-null <dfn id=uhus-serializeddata><var>serializedData</var></dfn> (default
  null), and an optional <a href=#history-handling-behavior id=navigate-non-frag-sync:history-handling-behavior>history handling behavior</a> <dfn id=uhus-historyhandling><var id=uhus-ispush>historyHandling</var></dfn> (default "<code id=navigate-non-frag-sync:navigationhistorybehavior-replace><a href=#navigationhistorybehavior-replace>replace</a></code>"), are:</p>

  <ol><li><p>Let <var>navigable</var> be <var>document</var>'s <a id=navigate-non-frag-sync:node-navigable href=document-sequences.html#node-navigable>node navigable</a>.<li><p>Let <var>activeEntry</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=navigate-non-frag-sync:nav-active-history-entry-2>active session history entry</a>.<li>
    <p>Let <var>newEntry</var> be a new <a href=#session-history-entry id=navigate-non-frag-sync:session-history-entry-2>session history entry</a>, with</p>

    <dl class=props><dt><a href=#she-url id=navigate-non-frag-sync:she-url>URL</a><dd><var>newURL</var><dt><a href=#she-classic-history-api-state id=navigate-non-frag-sync:she-classic-history-api-state>serialized state</a><dd>if <var>serializedData</var> is not null, <var>serializedData</var>; otherwise
     <var>activeEntry</var>'s <a href=#she-classic-history-api-state id=navigate-non-frag-sync:she-classic-history-api-state-2>classic history API
     state</a><dt><a href=#she-document-state id=navigate-non-frag-sync:she-document-state>document state</a><dd><var>activeEntry</var>'s <a href=#she-document-state id=navigate-non-frag-sync:she-document-state-2>document state</a><dt><a href=#she-scroll-restoration-mode id=navigate-non-frag-sync:she-scroll-restoration-mode>scroll restoration mode</a><dd><var>activeEntry</var>'s <a href=#she-scroll-restoration-mode id=navigate-non-frag-sync:she-scroll-restoration-mode-2>scroll restoration
     mode</a><dt><a href=#she-other id=navigate-non-frag-sync:she-other>persisted user state</a><dd><var>activeEntry</var>'s <a href=#she-other id=navigate-non-frag-sync:she-other-2>persisted user state</a></dl>
   <li>
    <p>If <var>document</var>'s <a id=navigate-non-frag-sync:is-initial-about:blank href=dom.html#is-initial-about:blank>is initial <code>about:blank</code></a> is true, then set
    <var>historyHandling</var> to "<code id=navigate-non-frag-sync:navigationhistorybehavior-replace-2><a href=#navigationhistorybehavior-replace>replace</a></code>".</p>

    <p class=note>This means that <code id=navigate-non-frag-sync:dom-history-pushstate-2><a href=nav-history-apis.html#dom-history-pushstate>pushState()</a></code> on an
    <a href=dom.html#is-initial-about:blank id=navigate-non-frag-sync:is-initial-about:blank-2>initial <code>about:blank</code></a>
    <code id=navigate-non-frag-sync:document-2><a href=dom.html#document>Document</a></code> behaves as a <code id=navigate-non-frag-sync:dom-history-replacestate-2><a href=nav-history-apis.html#dom-history-replacestate>replaceState()</a></code> call.</p>
   <li><p>Let <var>entryToReplace</var> be <var>activeEntry</var> if <var>historyHandling</var> is
   "<code id=navigate-non-frag-sync:navigationhistorybehavior-replace-3><a href=#navigationhistorybehavior-replace>replace</a></code>", otherwise null.<li>
    <p>If <var>historyHandling</var> is "<code id=navigate-non-frag-sync:navigationhistorybehavior-push><a href=#navigationhistorybehavior-push>push</a></code>",
    then:</p>

    <ol><li><p>Increment <var>document</var>'s <a href=nav-history-apis.html#doc-history id=navigate-non-frag-sync:doc-history>history object</a>'s
     <a href=nav-history-apis.html#concept-history-index id=navigate-non-frag-sync:concept-history-index>index</a>.<li><p>Set <var>document</var>'s <a href=nav-history-apis.html#doc-history id=navigate-non-frag-sync:doc-history-2>history object</a>'s <a href=nav-history-apis.html#concept-history-length id=navigate-non-frag-sync:concept-history-length>length</a> to its <a href=nav-history-apis.html#concept-history-index id=navigate-non-frag-sync:concept-history-index-2>index</a> + 1.</ol>

    <p class=note>These are temporary best-guess values for immediate synchronous access.</p>
   <li><p>If <var>serializedData</var> is not null, then <a href=#restore-the-history-object-state id=navigate-non-frag-sync:restore-the-history-object-state>restore the history object
   state</a> given <var>document</var> and <var>newEntry</var>.<li>
    <p><a id=navigate-non-frag-sync:set-the-url href=urls-and-fetching.html#set-the-url>Set the URL</a> given <var>document</var> to <var>newURL</var>.</p>

    <p class=note>Since this is neither a <a href=#navigate id=navigate-non-frag-sync:navigate-2>navigation</a> nor a <a href=#traverse-the-history-by-a-delta id=navigate-non-frag-sync:traverse-the-history-by-a-delta>history traversal</a>, it does not cause a <code id=navigate-non-frag-sync:event-hashchange><a href=indices.html#event-hashchange>hashchange</a></code> event to be fired.</p>
   <li><p>Set <var>document</var>'s <a href=#latest-entry id=navigate-non-frag-sync:latest-entry>latest entry</a> to <var>newEntry</var>.<li><p>Set <var>navigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=navigate-non-frag-sync:nav-active-history-entry-3>active session history
   entry</a> to <var>newEntry</var>.<li><p><a id=navigate-non-frag-sync:update-the-navigation-api-entries-for-a-same-document-navigation href=nav-history-apis.html#update-the-navigation-api-entries-for-a-same-document-navigation>Update the navigation API entries for a same-document navigation</a> given
   <var>document</var>'s <a id=navigate-non-frag-sync:concept-relevant-global href=webappapis.html#concept-relevant-global>relevant global object</a>'s <a href=nav-history-apis.html#window-navigation-api id=navigate-non-frag-sync:window-navigation-api>navigation API</a>, <var>newEntry</var>, and
   <var>historyHandling</var>.<li><p>Let <var>traversable</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-traversable id=navigate-non-frag-sync:nav-traversable>traversable navigable</a>.<li>
    <p><a href=#tn-append-session-history-sync-nav-steps id=navigate-non-frag-sync:tn-append-session-history-sync-nav-steps>Append the following session history
    synchronous navigation steps</a> involving <var>navigable</var> to
    <var>traversable</var>:</p>

    <ol><li><p><a href=#finalize-a-same-document-navigation id=navigate-non-frag-sync:finalize-a-same-document-navigation>Finalize a same-document navigation</a> given <var>traversable</var>,
     <var>navigable</var>, <var>newEntry</var>, <var>entryToReplace</var>,
     <var>historyHandling</var>, and "<code id=navigate-non-frag-sync:uni-none><a href=#uni-none>none</a></code>".<li><p>Invoke <a id=navigate-non-frag-sync:webdriver-bidi-history-updated href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-history-updated data-x-internal=webdriver-bidi-history-updated>WebDriver BiDi history updated</a> with <var>navigable</var>.</ol>
   </ol>

  <p class=note>Although both <a href=#navigate-fragid id=navigate-non-frag-sync:navigate-fragid>fragment navigation</a> and the
  <a href=#url-and-history-update-steps id=navigate-non-frag-sync:url-and-history-update-steps-2>URL and history update steps</a> perform synchronous history updates, only fragment
  navigation contains a synchronous call to <a href=#update-document-for-history-step-application id=navigate-non-frag-sync:update-document-for-history-step-application>update document for history step
  application</a>. The <a href=#url-and-history-update-steps id=navigate-non-frag-sync:url-and-history-update-steps-3>URL and history update steps</a> instead perform a few select
  updates inside the above algorithm, omitting others. This is somewhat of an unfortunate
  historical accident, and generally leads to <a href=https://github.com/whatwg/html/issues/5562>web-developer sadness</a> about the
  inconsistency. For example, this means that <code id=navigate-non-frag-sync:event-popstate><a href=indices.html#event-popstate>popstate</a></code> events
  fire for fragment navigations, but not for <code id=navigate-non-frag-sync:dom-history-pushstate-3><a href=nav-history-apis.html#dom-history-pushstate>history.pushState()</a></code> calls.</p>


  <h4 id=populating-a-session-history-entry><span class=secno>7.4.5</span> <span id=history-traversal></span><span id=traverse-the-history></span>Populating a session history entry<a href=#populating-a-session-history-entry class=self-link></a></h4>

  <p>As explained in <a href=#history>the overview</a>, both <a href=#navigating-across-documents>navigation</a> and <a href=#reloading-and-traversing>traversal</a> involve creating a <a href=#session-history-entry id=populating-a-session-history-entry:session-history-entry>session history
  entry</a> and then attempting to populate its <a href=#she-document id=populating-a-session-history-entry:she-document>document</a>
  member, so that it can be presented inside the <a id=populating-a-session-history-entry:navigable href=document-sequences.html#navigable>navigable</a>.</p>

  <p>This involves either: using <a href=#note-navigate-called-with-response>an already-given
  response</a>; using the <a href=#document-state-resource id=populating-a-session-history-entry:document-state-resource>srcdoc resource</a> stored in
  the <a href=#session-history-entry id=populating-a-session-history-entry:session-history-entry-2>session history entry</a>; or <a href=#create-navigation-params-by-fetching id=populating-a-session-history-entry:create-navigation-params-by-fetching>fetching</a>. The process has several failure modes, which can either result in
  doing nothing (leaving the <a id=populating-a-session-history-entry:navigable-2 href=document-sequences.html#navigable>navigable</a> on its currently-<a href=document-sequences.html#nav-document id=populating-a-session-history-entry:nav-document>active</a> <code id=populating-a-session-history-entry:document><a href=dom.html#document>Document</a></code>) or can result in populating the
  <a href=#session-history-entry id=populating-a-session-history-entry:session-history-entry-3>session history entry</a> with an <a href=document-lifecycle.html#read-ua-inline id=populating-a-session-history-entry:read-ua-inline>error
  document</a>.</p>

  <p>To <dfn id="attempt-to-populate-the-history-entry's-document">attempt to populate the history entry's document</dfn> for a <a href=#session-history-entry id=populating-a-session-history-entry:session-history-entry-4>session history
  entry</a> <var>entry</var>, given a <a id=populating-a-session-history-entry:navigable-3 href=document-sequences.html#navigable>navigable</a> <var>navigable</var>, a
  <code id=populating-a-session-history-entry:navigationtimingtype><a data-x-internal=navigationtimingtype href=https://w3c.github.io/navigation-timing/#dom-navigationtimingtype>NavigationTimingType</a></code> <var>navTimingType</var>, a <a href=#source-snapshot-params id=populating-a-session-history-entry:source-snapshot-params>source snapshot params</a>
  <var>sourceSnapshotParams</var>, a <a href=#target-snapshot-params id=populating-a-session-history-entry:target-snapshot-params>target snapshot params</a>
  <var>targetSnapshotParams</var>, a <a href=#user-navigation-involvement id=populating-a-session-history-entry:user-navigation-involvement>user navigation involvement</a>
  <var>userInvolvement</var>, an optional <a href=#navigation-id id=populating-a-session-history-entry:navigation-id>navigation ID</a>-or-null <var>navigationId</var>
  (default null), an optional <a href=#navigation-params id=populating-a-session-history-entry:navigation-params>navigation params</a>-or-null <var>navigationParams</var>
  (default null), an optional string <var>cspNavigationType</var> (default "<code>other</code>"), an optional boolean <dfn id=attempt-to-populate-allow-post><var>allowPOST</var></dfn> (default false), and optional
  algorithm steps <dfn id=attempt-to-populate-completion-steps><var>completionSteps</var></dfn> (default an empty
  algorithm):</p>

  <ol><li><p><a id=populating-a-session-history-entry:assert href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: this is running <a id=populating-a-session-history-entry:in-parallel href=infrastructure.html#in-parallel>in parallel</a>.<li><p><a id=populating-a-session-history-entry:assert-2 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: if <var>navigationParams</var> is non-null, then
   <var>navigationParams</var>'s <a href=#navigation-params-response id=populating-a-session-history-entry:navigation-params-response>response</a> is
   non-null.<li><p>Let <var>documentResource</var> be <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state>document state</a>'s <a href=#document-state-resource id=populating-a-session-history-entry:document-state-resource-2>resource</a>.<li>
    <p>If <var>navigationParams</var> is null, then:</p>

    <ol><li><p>If <var>documentResource</var> is a string, then set <var>navigationParams</var> to the
     result of <a href=#create-navigation-params-from-a-srcdoc-resource id=populating-a-session-history-entry:create-navigation-params-from-a-srcdoc-resource>creating navigation
     params from a srcdoc resource</a> given <var>entry</var>, <var>navigable</var>,
     <var>targetSnapshotParams</var>, <var>userInvolvement</var>, <var>navigationId</var>, and
     <var>navTimingType</var>.<li>
      <p>Otherwise, if all of the following are true:

      <ul><li><p><var>entry</var>'s <a href=#she-url id=populating-a-session-history-entry:she-url>URL</a>'s <a href=https://url.spec.whatwg.org/#concept-url-scheme id=populating-a-session-history-entry:concept-url-scheme data-x-internal=concept-url-scheme>scheme</a> is a <a id=populating-a-session-history-entry:fetch-scheme href=https://fetch.spec.whatwg.org/#fetch-scheme data-x-internal=fetch-scheme>fetch scheme</a>; and<li><p><var>documentResource</var> is null, or <var>allowPOST</var> is true and
       <var>documentResource</var>'s <a href=#post-resource-request-body id=populating-a-session-history-entry:post-resource-request-body>request body</a>
       is not failure,</ul>

      <p>then set <var>navigationParams</var> to the result of <a href=#create-navigation-params-by-fetching id=populating-a-session-history-entry:create-navigation-params-by-fetching-2>creating navigation params by fetching</a> given <var>entry</var>,
      <var>navigable</var>, <var>sourceSnapshotParams</var>, <var>targetSnapshotParams</var>,
      <var>cspNavigationType</var>, <var>userInvolvement</var>, <var>navigationId</var>, and
      <var>navTimingType</var>.</p>
     <li>
      <p>Otherwise, if <var>entry</var>'s <a href=#she-url id=populating-a-session-history-entry:she-url-2>URL</a>'s <a href=https://url.spec.whatwg.org/#concept-url-scheme id=populating-a-session-history-entry:concept-url-scheme-2 data-x-internal=concept-url-scheme>scheme</a> is not a <a id=populating-a-session-history-entry:fetch-scheme-2 href=https://fetch.spec.whatwg.org/#fetch-scheme data-x-internal=fetch-scheme>fetch scheme</a>, then set
      <var>navigationParams</var> to a new <a href=#non-fetch-scheme-navigation-params id=populating-a-session-history-entry:non-fetch-scheme-navigation-params>non-fetch scheme navigation params</a>,
      with</p>

      <dl class=props><dt><a href=#non-fetch-scheme-params-id id=populating-a-session-history-entry:non-fetch-scheme-params-id>id</a><dd><var>navigationId</var><dt><a href=#non-fetch-scheme-params-navigable id=populating-a-session-history-entry:non-fetch-scheme-params-navigable>navigable</a><dd><var>navigable</var><dt><a href=#non-fetch-scheme-params-url id=populating-a-session-history-entry:non-fetch-scheme-params-url>URL</a><dd><var>entry</var>'s <a href=#she-url id=populating-a-session-history-entry:she-url-3>URL</a><dt><a href=#non-fetch-scheme-params-target-sandbox id=populating-a-session-history-entry:non-fetch-scheme-params-target-sandbox>target snapshot sandboxing flags</a><dd><var>targetSnapshotParams</var>'s <a href=#target-snapshot-params-sandbox id=populating-a-session-history-entry:target-snapshot-params-sandbox>sandboxing flags</a><dt><a href=#non-fetch-scheme-params-source-activation id=populating-a-session-history-entry:non-fetch-scheme-params-source-activation>source snapshot has transient activation</a><dd><var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-activation id=populating-a-session-history-entry:source-snapshot-params-activation>has
       transient activation</a><dt><a href=#non-fetch-scheme-params-initiator-origin id=populating-a-session-history-entry:non-fetch-scheme-params-initiator-origin>initiator origin</a><dd><var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-2>document state</a>'s <a href=#document-state-initiator-origin id=populating-a-session-history-entry:document-state-initiator-origin>initiator origin</a><dt><a href=#non-fetch-scheme-params-nav-timing-type id=populating-a-session-history-entry:non-fetch-scheme-params-nav-timing-type>navigation timing type</a><dd><var>navTimingType</var><dt><a href=#non-fetch-scheme-params-user-involvement id=populating-a-session-history-entry:non-fetch-scheme-params-user-involvement>user involvement</a><dd><var>userInvolvement</var></dl>
     </ol>
   <li id=process-a-navigate-response>
    <p><a id=populating-a-session-history-entry:queue-a-global-task href=webappapis.html#queue-a-global-task>Queue a global task</a> on the <a id=populating-a-session-history-entry:navigation-and-traversal-task-source href=webappapis.html#navigation-and-traversal-task-source>navigation and traversal task source</a>,
    given <var>navigable</var>'s <a id=populating-a-session-history-entry:active-window href=document-sequences.html#active-window>active window</a>, to run these steps:</p>

    <ol><li><p>If <var>navigable</var>'s <a href=#ongoing-navigation id=populating-a-session-history-entry:ongoing-navigation>ongoing navigation</a> no longer equals
     <var>navigationId</var>, then run <var>completionSteps</var> and abort these steps.<li>
      <p>Let <var>saveExtraDocumentState</var> be true.</p>

      <div class=note>
       <p>Usually, in the cases where we end up populating <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-3>document state</a>'s <a href=#document-state-document id=populating-a-session-history-entry:document-state-document>document</a>, we then want to save some of the state
       from that <code id=populating-a-session-history-entry:document-2><a href=dom.html#document>Document</a></code> into <var>entry</var>. This ensures that if there are future
       traversals to <var>entry</var> where its <a href=#document-state-document id=populating-a-session-history-entry:document-state-document-2>document</a> <a href=#note-bfcache>has been
       destroyed</a>, we can use that state when creating a new <code id=populating-a-session-history-entry:document-3><a href=dom.html#document>Document</a></code>.</p>

       <p>However, in some specific cases, saving the state would be unhelpful. For those, we set
       <var>saveExtraDocumentState</var> to false later in this algorithm.</p>
      </div>
     <li>
      <p>If <var>navigationParams</var> is a <a href=#non-fetch-scheme-navigation-params id=populating-a-session-history-entry:non-fetch-scheme-navigation-params-2>non-fetch scheme navigation params</a>,
      then:</p>

      <ol><li>
        <p>Set <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-4>document state</a>'s <a href=#document-state-document id=populating-a-session-history-entry:document-state-document-3>document</a> to the result of running <a href=#attempt-to-create-a-non-fetch-scheme-document id=populating-a-session-history-entry:attempt-to-create-a-non-fetch-scheme-document>attempt to
        create a non-fetch scheme document</a> given <var>navigationParams</var>.</p>

        <p class=note>This can result in setting <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-5>document state</a>'s <a href=#document-state-document id=populating-a-session-history-entry:document-state-document-4>document</a> to null, e.g., when <a href=#hand-off-to-external-software id=populating-a-session-history-entry:hand-off-to-external-software>handing-off to external software</a>.</p>
       <li><p>Set <var>saveExtraDocumentState</var> to false.</ol>
     <li>
      <p>Otherwise, if any of the following are true:</p>

      <ul><li><p><var>navigationParams</var> is null;<li><p>the result of <a id=populating-a-session-history-entry:should-navigation-response-to-navigation-request-of-type-in-target-be-blocked-by-content-security-policy href=https://w3c.github.io/webappsec-csp/#should-block-navigation-response data-x-internal=should-navigation-response-to-navigation-request-of-type-in-target-be-blocked-by-content-security-policy>should navigation response to navigation request of type in
       target be blocked by Content Security Policy?</a> given <var>navigationParams</var>'s
       <a href=#navigation-params-request id=populating-a-session-history-entry:navigation-params-request>request</a>, <var>navigationParams</var>'s <a href=#navigation-params-response id=populating-a-session-history-entry:navigation-params-response-2>response</a>, <var>navigationParams</var>'s <a href=#navigation-params-policy-container id=populating-a-session-history-entry:navigation-params-policy-container>policy container</a>'s <a href=browsers.html#policy-container-csp-list id=populating-a-session-history-entry:policy-container-csp-list>CSP list</a>, <var>cspNavigationType</var>, and
       <var>navigable</var> is "<code>Blocked</code>";<li><p><var>navigationParams</var>'s <a href=#navigation-params-reserved-environment id=populating-a-session-history-entry:navigation-params-reserved-environment>reserved environment</a> is non-null and
       the result of <a href="browsers.html#check-a-navigation-response's-adherence-to-its-embedder-policy" id="populating-a-session-history-entry:check-a-navigation-response's-adherence-to-its-embedder-policy">checking a navigation response's adherence to its embedder policy</a> given
       <var>navigationParams</var>'s <a href=#navigation-params-response id=populating-a-session-history-entry:navigation-params-response-3>response</a>,
       <var>navigable</var>, and <var>navigationParams</var>'s <a href=#navigation-params-policy-container id=populating-a-session-history-entry:navigation-params-policy-container-2>policy container</a>'s <a href=browsers.html#policy-container-embedder-policy id=populating-a-session-history-entry:policy-container-embedder-policy>embedder policy</a> is false; or <li><p>the result of <a href="speculative-loading.html#check-a-navigation-response's-adherence-to-x-frame-options" id="populating-a-session-history-entry:check-a-navigation-response's-adherence-to-x-frame-options">checking a navigation response's adherence to
       `<code>X-Frame-Options</code>`</a> given <var>navigationParams</var>'s <a href=#navigation-params-response id=populating-a-session-history-entry:navigation-params-response-4>response</a>, <var>navigable</var>,
       <var>navigationParams</var>'s <a href=#navigation-params-policy-container id=populating-a-session-history-entry:navigation-params-policy-container-3>policy
       container</a>'s <a href=browsers.html#policy-container-csp-list id=populating-a-session-history-entry:policy-container-csp-list-2>CSP list</a>, and
       <var>navigationParams</var>'s <a href=#navigation-params-origin id=populating-a-session-history-entry:navigation-params-origin>origin</a> is
       false,</ul>

      <p>then:</p>

      <ol><li><p>Set <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-6>document state</a>'s
       <a href=#document-state-document id=populating-a-session-history-entry:document-state-document-5>document</a> to the result of <a href=document-lifecycle.html#read-ua-inline id=populating-a-session-history-entry:read-ua-inline-2>creating a document for inline content that doesn't have a
       DOM</a>, given <var>navigable</var>, null, <var>navTimingType</var>, and
       <var>userInvolvement</var>. The inline content should indicate to the user the sort of error
       that occurred.<li><p><a href=#make-document-unsalvageable id=populating-a-session-history-entry:make-document-unsalvageable>Make document unsalvageable</a> given <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-7>document state</a>'s <a href=#document-state-document id=populating-a-session-history-entry:document-state-document-6>document</a> and "<code id=populating-a-session-history-entry:blocking-navigation-failure><a href=nav-history-apis.html#blocking-navigation-failure>navigation-failure</a></code>".<li><p>Set <var>saveExtraDocumentState</var> to false.<li>
        <p>If <var>navigationParams</var> is not null, then:</p>

        <ol><li><p>Run the <a href=webappapis.html#environment-discarding-steps id=populating-a-session-history-entry:environment-discarding-steps>environment discarding
         steps</a> for <var>navigationParams</var>'s <a href=#navigation-params-reserved-environment id=populating-a-session-history-entry:navigation-params-reserved-environment-2>reserved environment</a>.<li><p>Invoke <a id=populating-a-session-history-entry:webdriver-bidi-navigation-failed href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-navigation-failed data-x-internal=webdriver-bidi-navigation-failed>WebDriver BiDi navigation failed</a> with <var>navigable</var> and a
         new <a id=populating-a-session-history-entry:webdriver-bidi-navigation-status href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-navigation-status data-x-internal=webdriver-bidi-navigation-status>WebDriver BiDi navigation status</a> whose <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-id id=populating-a-session-history-entry:navigation-status-id data-x-internal=navigation-status-id>id</a> is <var>navigationId</var>, <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-status id=populating-a-session-history-entry:navigation-status-status data-x-internal=navigation-status-status>status</a> is "<code id=populating-a-session-history-entry:navigation-status-canceled><a data-x-internal=navigation-status-canceled href=https://w3c.github.io/webdriver-bidi/#navigation-status-canceled>canceled</a></code>", and <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-url id=populating-a-session-history-entry:navigation-status-url data-x-internal=navigation-status-url>url</a> is <var>navigationParams</var>'s <a href=#navigation-params-response id=populating-a-session-history-entry:navigation-params-response-5>response</a>'s <a href=https://fetch.spec.whatwg.org/#concept-response-url id=populating-a-session-history-entry:concept-response-url data-x-internal=concept-response-url>URL</a>.</ol>
       </ol>
     <li id=navigation-as-a-download>
      <p>Otherwise, if <var>navigationParams</var>'s <a href=#navigation-params-response id=populating-a-session-history-entry:navigation-params-response-6>response</a> has a `<code id=populating-a-session-history-entry:http-content-disposition><a data-x-internal=http-content-disposition href=https://httpwg.org/specs/rfc6266.html>Content-Disposition</a></code>` header specifying the <code>attachment</code> disposition type, then:</p>

      <ol><li><p>Let <var>sourceAllowsDownloading</var> be <var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-download id=populating-a-session-history-entry:source-snapshot-params-download>allows downloading</a>.<li><p>Let <var>targetAllowsDownloading</var> be false if <var>navigationParams</var>'s
       <a href=#navigation-params-sandboxing id=populating-a-session-history-entry:navigation-params-sandboxing>final sandboxing flag set</a> has the
       <a id=populating-a-session-history-entry:sandboxed-downloads-browsing-context-flag href=browsers.html#sandboxed-downloads-browsing-context-flag>sandboxed downloads browsing context flag</a> set; otherwise true.<li><p>Let <var>uaAllowsDownloading</var> be true.<li><p>Optionally, the user agent may set <var>uaAllowsDownloading</var> to false, if it
       believes doing so would safeguard the user from a potentially hostile download.<li>
        <p>If <var>sourceAllowsDownloading</var>, <var>targetAllowsDownloading</var>, and
        <var>uaAllowsDownloading</var> are true, then:</p>

        <ol><li><p>Let <var>suggestedFilename</var> be the result of <a href=links.html#handle-as-a-download id=populating-a-session-history-entry:handle-as-a-download>handling as a download</a> <var>navigationParams</var>'s <a href=#navigation-params-response id=populating-a-session-history-entry:navigation-params-response-7>response</a>.<li><p>Invoke <a id=populating-a-session-history-entry:webdriver-bidi-download-started href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-download-started data-x-internal=webdriver-bidi-download-started>WebDriver BiDi download started</a> with <var>navigable</var> and a
         new <a id=populating-a-session-history-entry:webdriver-bidi-navigation-status-2 href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-navigation-status data-x-internal=webdriver-bidi-navigation-status>WebDriver BiDi navigation status</a> whose <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-id id=populating-a-session-history-entry:navigation-status-id-2 data-x-internal=navigation-status-id>id</a> is <var>navigationId</var>, <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-status id=populating-a-session-history-entry:navigation-status-status-2 data-x-internal=navigation-status-status>status</a> is "<code id=populating-a-session-history-entry:navigation-status-complete><a data-x-internal=navigation-status-complete href=https://w3c.github.io/webdriver-bidi/#navigation-status-complete>complete</a></code>", <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-url id=populating-a-session-history-entry:navigation-status-url-2 data-x-internal=navigation-status-url>url</a> is <var>navigationParams</var>'s <a href=#navigation-params-response id=populating-a-session-history-entry:navigation-params-response-8>response</a>'s <a href=https://fetch.spec.whatwg.org/#concept-response-url id=populating-a-session-history-entry:concept-response-url-2 data-x-internal=concept-response-url>URL</a>, and <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-suggested-filename id=populating-a-session-history-entry:navigation-status-suggested-filename data-x-internal=navigation-status-suggested-filename>suggestedFilename</a> is
         <var>suggestedFilename</var>.</ol>
       </ol>

      <p class=note>This branch leaves <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-8>document state</a>'s <a href=#document-state-document id=populating-a-session-history-entry:document-state-document-7>document</a> as null.</p>
     <li>
      <p>Otherwise, if <var>navigationParams</var>'s <a href=#navigation-params-response id=populating-a-session-history-entry:navigation-params-response-9>response</a>'s <a href=https://fetch.spec.whatwg.org/#concept-response-status id=populating-a-session-history-entry:concept-response-status data-x-internal=concept-response-status>status</a> is not 204 and is not 205, then set
      <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-9>document state</a>'s <a href=#document-state-document id=populating-a-session-history-entry:document-state-document-8>document</a> to the result of <a href=#loading-a-document id=populating-a-session-history-entry:loading-a-document>loading a
      document</a> given <var>navigationParams</var>, <var>sourceSnapshotParams</var>, and
      <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-10>document state</a>'s <a href=#document-state-initiator-origin id=populating-a-session-history-entry:document-state-initiator-origin-2>initiator origin</a>.</p>

      <p class=note>This can result in setting <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-11>document state</a>'s <a href=#document-state-document id=populating-a-session-history-entry:document-state-document-9>document</a> to null, e.g., when <a href=#hand-off-to-external-software id=populating-a-session-history-entry:hand-off-to-external-software-2>handing-off to external software</a>.</p>
     <li>
      <p>If <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-12>document state</a>'s <a href=#document-state-document id=populating-a-session-history-entry:document-state-document-10>document</a> is not null, then:</p>

      <ol><li><p>Set <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-13>document state</a>'s
       <a href=#document-state-ever-populated id=populating-a-session-history-entry:document-state-ever-populated>ever populated</a> to true.<li>
        <p>If <var>saveExtraDocumentState</var> is true:</p>

        <ol><li><p>Let <var>document</var> be <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-14>document state</a>'s <a href=#document-state-document id=populating-a-session-history-entry:document-state-document-11>document</a>.<li><p>Set <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-15>document state</a>'s
         <a href=#document-state-origin id=populating-a-session-history-entry:document-state-origin>origin</a> to <var>document</var>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=populating-a-session-history-entry:concept-document-origin data-x-internal=concept-document-origin>origin</a>.<li>
          <p>If <var>document</var>'s <a href=https://dom.spec.whatwg.org/#concept-document-url id="populating-a-session-history-entry:the-document's-address" data-x-internal="the-document's-address">URL</a>
          <a id=populating-a-session-history-entry:requires-storing-the-policy-container-in-history href=browsers.html#requires-storing-the-policy-container-in-history>requires storing the policy container in history</a>, then:</p>

          <ol><li><p><a id=populating-a-session-history-entry:assert-3 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>navigationParams</var> is a <a href=#navigation-params id=populating-a-session-history-entry:navigation-params-2>navigation
           params</a> (i.e., neither null nor a <a href=#non-fetch-scheme-navigation-params id=populating-a-session-history-entry:non-fetch-scheme-navigation-params-3>non-fetch scheme navigation
           params</a>).<li><p>Set <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-16>document state</a>'s
           <a href=#document-state-history-policy-container id=populating-a-session-history-entry:document-state-history-policy-container>history policy container</a>
           to <var>navigationParams</var>'s <a href=#navigation-params-policy-container id=populating-a-session-history-entry:navigation-params-policy-container-4>policy container</a>.</ol>
         </ol>
       <li>
        <p>If <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-17>document state</a>'s <a href=#document-state-request-referrer id=populating-a-session-history-entry:document-state-request-referrer>request referrer</a> is "<code>client</code>", and <var>navigationParams</var> is a <a href=#navigation-params id=populating-a-session-history-entry:navigation-params-3>navigation
        params</a> (i.e., neither null nor a <a href=#non-fetch-scheme-navigation-params id=populating-a-session-history-entry:non-fetch-scheme-navigation-params-4>non-fetch scheme navigation params</a>),
        then:</p>

        <ol><li><p><a id=populating-a-session-history-entry:assert-4 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>navigationParams</var>'s <a href=#navigation-params-request id=populating-a-session-history-entry:navigation-params-request-2>request</a> is not null.<li><p>Set <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-18>document state</a>'s
         <a href=#document-state-request-referrer id=populating-a-session-history-entry:document-state-request-referrer-2>request referrer</a> to
         <var>navigationParams</var>'s <a href=#navigation-params-request id=populating-a-session-history-entry:navigation-params-request-3>request</a>'s
         <a href=https://fetch.spec.whatwg.org/#concept-request-referrer id=populating-a-session-history-entry:concept-request-referrer data-x-internal=concept-request-referrer>referrer</a>.</ol>
       </ol>
     <li><p>Run <var>completionSteps</var>.</ol>
   </ol>

  <p>To <dfn id=create-navigation-params-from-a-srcdoc-resource>create navigation params from a srcdoc resource</dfn> given a <a href=#session-history-entry id=populating-a-session-history-entry:session-history-entry-5>session history
  entry</a> <var>entry</var>, a <a id=populating-a-session-history-entry:navigable-4 href=document-sequences.html#navigable>navigable</a> <var>navigable</var>, a <a href=#target-snapshot-params id=populating-a-session-history-entry:target-snapshot-params-2>target
  snapshot params</a> <var>targetSnapshotParams</var>, a <a href=#user-navigation-involvement id=populating-a-session-history-entry:user-navigation-involvement-2>user navigation involvement</a>
  <var>userInvolvement</var>, a <a href=#navigation-id id=populating-a-session-history-entry:navigation-id-2>navigation ID</a>-or-null <var>navigationId</var>, and a
  <code id=populating-a-session-history-entry:navigationtimingtype-2><a data-x-internal=navigationtimingtype href=https://w3c.github.io/navigation-timing/#dom-navigationtimingtype>NavigationTimingType</a></code> <var>navTimingType</var>:</p>

  <ol><li><p>Let <var>documentResource</var> be <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-19>document state</a>'s <a href=#document-state-resource id=populating-a-session-history-entry:document-state-resource-3>resource</a>.<li>
    <p>Let <var>response</var> be a new <a href=https://fetch.spec.whatwg.org/#concept-response id=populating-a-session-history-entry:concept-response data-x-internal=concept-response>response</a> with</p>

    <dl class=props><dt><a href=https://fetch.spec.whatwg.org/#concept-response-url id=populating-a-session-history-entry:concept-response-url-3 data-x-internal=concept-response-url>URL</a><dd><code id=populating-a-session-history-entry:about:srcdoc><a href=urls-and-fetching.html#about:srcdoc>about:srcdoc</a></code><dt><a href=https://fetch.spec.whatwg.org/#concept-response-header-list id=populating-a-session-history-entry:concept-response-header-list data-x-internal=concept-response-header-list>header list</a><dd>« (`<code id=populating-a-session-history-entry:content-type><a href=urls-and-fetching.html#content-type>Content-Type</a></code>`, `<code>text/html</code>`) »<dt><a href=https://fetch.spec.whatwg.org/#concept-response-body id=populating-a-session-history-entry:concept-response-body data-x-internal=concept-response-body>body</a><dd>the <a href=https://encoding.spec.whatwg.org/#utf-8-encode id=populating-a-session-history-entry:utf-8-encode data-x-internal=utf-8-encode>UTF-8 encoding</a> of <var>documentResource</var>,
     <a id=populating-a-session-history-entry:as-a-body href=https://fetch.spec.whatwg.org/#byte-sequence-as-a-body data-x-internal=as-a-body>as a body</a></dl>
   <li><p>Let <var>responseOrigin</var> be the result of <a id=populating-a-session-history-entry:determining-the-origin href=document-sequences.html#determining-the-origin>determining the origin</a> given
   <var>response</var>'s <a href=https://fetch.spec.whatwg.org/#concept-response-url id=populating-a-session-history-entry:concept-response-url-4 data-x-internal=concept-response-url>URL</a>,
   <var>targetSnapshotParams</var>'s <a href=#target-snapshot-params-sandbox id=populating-a-session-history-entry:target-snapshot-params-sandbox-2>sandboxing
   flags</a>, and <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-20>document state</a>'s
   <a href=#document-state-origin id=populating-a-session-history-entry:document-state-origin-2>origin</a>.<li><p>Let <var>coop</var> be a new <a id=populating-a-session-history-entry:cross-origin-opener-policy href=browsers.html#cross-origin-opener-policy>opener policy</a>.<li>
    <p>Let <var>coopEnforcementResult</var> be a new <a href=browsers.html#coop-enforcement-result id=populating-a-session-history-entry:coop-enforcement-result>opener
    policy enforcement result</a> with</p>

    <dl class=props><dt><a href=browsers.html#coop-enforcement-url id=populating-a-session-history-entry:coop-enforcement-url>url</a><dd><var>response</var>'s <a href=https://fetch.spec.whatwg.org/#concept-response-url id=populating-a-session-history-entry:concept-response-url-5 data-x-internal=concept-response-url>URL</a><dt><a href=browsers.html#coop-enforcement-origin id=populating-a-session-history-entry:coop-enforcement-origin>origin</a><dd><var>responseOrigin</var><dt><a href=browsers.html#coop-enforcement-coop id=populating-a-session-history-entry:coop-enforcement-coop>opener policy</a><dd><var>coop</var></dl>
   <li><p>Let <var>policyContainer</var> be the result of <a href=browsers.html#determining-navigation-params-policy-container id=populating-a-session-history-entry:determining-navigation-params-policy-container>determining navigation params policy container</a> given
   <var>response</var>'s <a href=https://fetch.spec.whatwg.org/#concept-response-url id=populating-a-session-history-entry:concept-response-url-6 data-x-internal=concept-response-url>URL</a>, <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-21>document state</a>'s <a href=#document-state-history-policy-container id=populating-a-session-history-entry:document-state-history-policy-container-2>history policy container</a>, null,
   <var>navigable</var>'s <a href=document-sequences.html#nav-container-document id=populating-a-session-history-entry:nav-container-document>container document</a>'s <a href=dom.html#concept-document-policy-container id=populating-a-session-history-entry:concept-document-policy-container>policy container</a>, and null.<li>
    <p>Return a new <a href=#navigation-params id=populating-a-session-history-entry:navigation-params-4>navigation params</a>, with</p>

    <dl class=props><dt><a href=#navigation-params-id id=populating-a-session-history-entry:navigation-params-id>id</a><dd><var>navigationId</var><dt><a href=#navigation-params-navigable id=populating-a-session-history-entry:navigation-params-navigable>navigable</a><dd><var>navigable</var><dt><a href=#navigation-params-request id=populating-a-session-history-entry:navigation-params-request-4>request</a><dd>null<dt><a href=#navigation-params-response id=populating-a-session-history-entry:navigation-params-response-10>response</a><dd><var>response</var><dt><a href=#navigation-params-fetch-controller id=populating-a-session-history-entry:navigation-params-fetch-controller>fetch controller</a><dd>null<dt><a href=#navigation-params-commit-early-hints id=populating-a-session-history-entry:navigation-params-commit-early-hints>commit early hints</a><dd>null<dt><a href=#navigation-params-coop-enforcement-result id=populating-a-session-history-entry:navigation-params-coop-enforcement-result>COOP enforcement result</a><dd><var>coopEnforcementResult</var><dt><a href=#navigation-params-reserved-environment id=populating-a-session-history-entry:navigation-params-reserved-environment-3>reserved environment</a><dd>null<dt><a href=#navigation-params-origin id=populating-a-session-history-entry:navigation-params-origin-2>origin</a><dd><var>responseOrigin</var><dt><a href=#navigation-params-policy-container id=populating-a-session-history-entry:navigation-params-policy-container-5>policy container</a><dd><var>policyContainer</var><dt><a href=#navigation-params-sandboxing id=populating-a-session-history-entry:navigation-params-sandboxing-2>final sandboxing flag set</a><dd><var>targetSnapshotParams</var>'s <a href=#target-snapshot-params-sandbox id=populating-a-session-history-entry:target-snapshot-params-sandbox-3>sandboxing
     flags</a><dt><a href=#navigation-params-coop id=populating-a-session-history-entry:navigation-params-coop>opener policy</a><dd><var>coop</var><dt><a href=#navigation-params-nav-timing-type id=populating-a-session-history-entry:navigation-params-nav-timing-type>navigation timing type</a><dd><var>navTimingType</var><dt><a href=#navigation-params-about-base-url id=populating-a-session-history-entry:navigation-params-about-base-url>about base URL</a><dd><var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-22>document state</a>'s <a href=#document-state-about-base-url id=populating-a-session-history-entry:document-state-about-base-url>about base URL</a><dt><a href=#navigation-params-user-involvement id=populating-a-session-history-entry:navigation-params-user-involvement>user involvement</a><dd><var>userInvolvement</var></dl>
   </ol>

  <p id=process-a-navigate-fetch>To <dfn id=create-navigation-params-by-fetching>create navigation params by fetching</dfn> given a
  <a href=#session-history-entry id=populating-a-session-history-entry:session-history-entry-6>session history entry</a> <var>entry</var>, a <a id=populating-a-session-history-entry:navigable-5 href=document-sequences.html#navigable>navigable</a>
  <var>navigable</var>, a <a href=#source-snapshot-params id=populating-a-session-history-entry:source-snapshot-params-2>source snapshot params</a> <var>sourceSnapshotParams</var>, a
  <a href=#target-snapshot-params id=populating-a-session-history-entry:target-snapshot-params-3>target snapshot params</a> <var>targetSnapshotParams</var>, a string
  <var>cspNavigationType</var>, a <a href=#user-navigation-involvement id=populating-a-session-history-entry:user-navigation-involvement-3>user navigation involvement</a>
  <var>userInvolvement</var>, a <a href=#navigation-id id=populating-a-session-history-entry:navigation-id-3>navigation ID</a>-or-null <var>navigationId</var>, and a
  <code id=populating-a-session-history-entry:navigationtimingtype-3><a data-x-internal=navigationtimingtype href=https://w3c.github.io/navigation-timing/#dom-navigationtimingtype>NavigationTimingType</a></code> <var>navTimingType</var>, perform the following steps. They
  return a <a href=#navigation-params id=populating-a-session-history-entry:navigation-params-5>navigation params</a>, a <a href=#non-fetch-scheme-navigation-params id=populating-a-session-history-entry:non-fetch-scheme-navigation-params-5>non-fetch scheme navigation params</a>, or
  null.</p>

  <p class=note>This algorithm mutates <var>entry</var>.</p>

  <ol><li><p><a id=populating-a-session-history-entry:assert-5 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: this is running <a id=populating-a-session-history-entry:in-parallel-2 href=infrastructure.html#in-parallel>in parallel</a>.<li><p>Let <var>documentResource</var> be <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-23>document state</a>'s <a href=#document-state-resource id=populating-a-session-history-entry:document-state-resource-4>resource</a>.<li>
    <p>Let <var>request</var> be a new <a href=https://fetch.spec.whatwg.org/#concept-request id=populating-a-session-history-entry:concept-request data-x-internal=concept-request>request</a>, with</p>

    <dl class=props><dt><a href=https://fetch.spec.whatwg.org/#concept-request-url id=populating-a-session-history-entry:concept-request-url data-x-internal=concept-request-url>url</a><dd><var>entry</var>'s <a href=#she-url id=populating-a-session-history-entry:she-url-4>URL</a><dt><a href=https://fetch.spec.whatwg.org/#concept-request-client id=populating-a-session-history-entry:concept-request-client data-x-internal=concept-request-client>client</a><dd><var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-client id=populating-a-session-history-entry:source-snapshot-params-client>fetch
     client</a><dt><a href=https://fetch.spec.whatwg.org/#concept-request-destination id=populating-a-session-history-entry:concept-request-destination data-x-internal=concept-request-destination>destination</a><dd>"<code>document</code>" <span class=note>The destination is updated below when
     <var>navigable</var> has a <a href=document-sequences.html#nav-container id=populating-a-session-history-entry:nav-container>container</a>.</span><dt><a href=https://fetch.spec.whatwg.org/#concept-request-credentials-mode id=populating-a-session-history-entry:concept-request-credentials-mode data-x-internal=concept-request-credentials-mode>credentials mode</a><dd>"<code>include</code>"<dt><a id=populating-a-session-history-entry:use-url-credentials-flag href=https://fetch.spec.whatwg.org/#concept-request-use-url-credentials-flag data-x-internal=use-url-credentials-flag>use-URL-credentials flag</a><dd>set<dt><a href=https://fetch.spec.whatwg.org/#concept-request-redirect-mode id=populating-a-session-history-entry:concept-request-redirect-mode data-x-internal=concept-request-redirect-mode>redirect mode</a><dd>"<code>manual</code>"<dt><a href=https://fetch.spec.whatwg.org/#concept-request-replaces-client-id id=populating-a-session-history-entry:concept-request-replaces-client-id data-x-internal=concept-request-replaces-client-id>replaces client id</a><dd><var>navigable</var>'s <a href=document-sequences.html#nav-document id=populating-a-session-history-entry:nav-document-2>active document</a>'s <a id=populating-a-session-history-entry:relevant-settings-object href=webappapis.html#relevant-settings-object>relevant
     settings object</a>'s <a href=webappapis.html#concept-environment-id id=populating-a-session-history-entry:concept-environment-id>id</a><dt><a href=https://fetch.spec.whatwg.org/#concept-request-mode id=populating-a-session-history-entry:concept-request-mode data-x-internal=concept-request-mode>mode</a><dd>"<code>navigate</code>"<dt><a href=https://fetch.spec.whatwg.org/#concept-request-referrer id=populating-a-session-history-entry:concept-request-referrer-2 data-x-internal=concept-request-referrer>referrer</a><dd><var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-24>document state</a>'s <a href=#document-state-request-referrer id=populating-a-session-history-entry:document-state-request-referrer-3>request referrer</a><dt><a href=https://fetch.spec.whatwg.org/#concept-request-referrer-policy id=populating-a-session-history-entry:concept-request-referrer-policy data-x-internal=concept-request-referrer-policy>referrer policy</a><dd><var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-25>document state</a>'s <a href=#document-state-request-referrer-policy id=populating-a-session-history-entry:document-state-request-referrer-policy>request referrer policy</a><dt><a href=https://fetch.spec.whatwg.org/#concept-request-policy-container id=populating-a-session-history-entry:concept-request-policy-container data-x-internal=concept-request-policy-container>policy container</a><dd><var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-policy-container id=populating-a-session-history-entry:source-snapshot-params-policy-container>source policy container</a><dt><a href=https://fetch.spec.whatwg.org/#concept-request-window id=populating-a-session-history-entry:concept-request-traversable-for-user-prompts data-x-internal=concept-request-traversable-for-user-prompts>traversable for user prompts</a><dd><var>navigable</var>'s <a href=document-sequences.html#nav-top id=populating-a-session-history-entry:nav-top>top-level traversable</a></dl>
   <li><p>If <var>navigable</var> is a <a id=populating-a-session-history-entry:top-level-traversable href=document-sequences.html#top-level-traversable>top-level traversable</a>, then set
   <var>request</var>'s <a id=populating-a-session-history-entry:top-level-navigation-initiator-origin href=https://fetch.spec.whatwg.org/#request-top-level-navigation-initiator-origin data-x-internal=top-level-navigation-initiator-origin>top-level navigation initiator origin</a> to <var>entry</var>'s
   <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-26>document state</a>'s <a href=#document-state-initiator-origin id=populating-a-session-history-entry:document-state-initiator-origin-3>initiator origin</a>.<li>
    <p>If <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-client id=populating-a-session-history-entry:concept-request-client-2 data-x-internal=concept-request-client>client</a> is null:</p>

    <p class=note>This <a href=#assert-null-sourcedocument>only occurs</a> in the case of a
    browser UI-initiated navigation.</p>

    <ol><li><p>Set <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-origin id=populating-a-session-history-entry:concept-request-origin data-x-internal=concept-request-origin>origin</a> to a new
     <a href=browsers.html#concept-origin-opaque id=populating-a-session-history-entry:concept-origin-opaque>opaque origin</a>.<li><p>Set <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#request-service-workers-mode id=populating-a-session-history-entry:concept-request-service-workers-mode data-x-internal=concept-request-service-workers-mode>service-workers mode</a> to "<code>all</code>".<li><p>Set <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-referrer id=populating-a-session-history-entry:concept-request-referrer-3 data-x-internal=concept-request-referrer>referrer</a> to
     "<code>no-referrer</code>".</ol>
   <li>
    <p>If <var>documentResource</var> is a <a href=#post-resource id=populating-a-session-history-entry:post-resource>POST resource</a>:</p>

    <ol><li><p>Set <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-method id=populating-a-session-history-entry:concept-request-method data-x-internal=concept-request-method>method</a> to `<code>POST</code>`.<li><p>Set <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-body id=populating-a-session-history-entry:concept-request-body data-x-internal=concept-request-body>body</a> to
     <var>documentResource</var>'s <a href=#post-resource-request-body id=populating-a-session-history-entry:post-resource-request-body-2>request
     body</a>.<li><p><a href=https://fetch.spec.whatwg.org/#concept-header-list-set id=populating-a-session-history-entry:concept-header-list-set data-x-internal=concept-header-list-set>Set</a> `<code>Content-Type</code>`
     to <var>documentResource</var>'s <a href=#post-resource-request-content-type id=populating-a-session-history-entry:post-resource-request-content-type>request
     content-type</a> in <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-header-list id=populating-a-session-history-entry:concept-request-header-list data-x-internal=concept-request-header-list>header
     list</a>.</ol>
   <li><p>If <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-27>document state</a>'s <a href=#document-state-reload-pending id=populating-a-session-history-entry:document-state-reload-pending>reload pending</a> is true, then set
   <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-reload-navigation-flag id=populating-a-session-history-entry:concept-request-reload-navigation-flag data-x-internal=concept-request-reload-navigation-flag>reload-navigation
   flag</a>.<li><p>Otherwise, if <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-28>document
   state</a>'s <a href=#document-state-ever-populated id=populating-a-session-history-entry:document-state-ever-populated-2>ever populated</a> is true, then
   set <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-history-navigation-flag id=populating-a-session-history-entry:concept-request-history-navigation-flag data-x-internal=concept-request-history-navigation-flag>history-navigation flag</a>.<li><p>If <var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-activation id=populating-a-session-history-entry:source-snapshot-params-activation-2>has
   transient activation</a> is true, then set <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#request-user-activation id=populating-a-session-history-entry:concept-request-user-activation data-x-internal=concept-request-user-activation>user-activation</a> to true.<li>
    <p>If <var>navigable</var>'s <a href=document-sequences.html#nav-container id=populating-a-session-history-entry:nav-container-2>container</a> is non-null:</p>

    <ol><li><p>If the <var>navigable</var>'s <a href=document-sequences.html#nav-container id=populating-a-session-history-entry:nav-container-3>container</a> has a
     <a href=#browsing-context-scope-origin id=populating-a-session-history-entry:browsing-context-scope-origin>browsing context scope origin</a>, then set <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-origin id=populating-a-session-history-entry:concept-request-origin-2 data-x-internal=concept-request-origin>origin</a> to that <a href=#browsing-context-scope-origin id=populating-a-session-history-entry:browsing-context-scope-origin-2>browsing context scope
     origin</a>.<li><p>Set <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-destination id=populating-a-session-history-entry:concept-request-destination-2 data-x-internal=concept-request-destination>destination</a>
     to <var>navigable</var>'s <a href=document-sequences.html#nav-container id=populating-a-session-history-entry:nav-container-4>container</a>'s <a href=https://dom.spec.whatwg.org/#concept-element-local-name id=populating-a-session-history-entry:concept-element-local-name data-x-internal=concept-element-local-name>local name</a>.<li>
      <p>If <var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-client id=populating-a-session-history-entry:source-snapshot-params-client-2>fetch
      client</a> is <var>navigable</var>'s <a href=document-sequences.html#nav-container-document id=populating-a-session-history-entry:nav-container-document-2>container
      document</a>'s <a id=populating-a-session-history-entry:relevant-settings-object-2 href=webappapis.html#relevant-settings-object>relevant settings object</a>, then set <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#request-initiator-type id=populating-a-session-history-entry:concept-request-initiator-type data-x-internal=concept-request-initiator-type>initiator type</a> to <var>navigable</var>'s <a href=document-sequences.html#nav-container id=populating-a-session-history-entry:nav-container-5>container</a>'s <a href=https://dom.spec.whatwg.org/#concept-element-local-name id=populating-a-session-history-entry:concept-element-local-name-2 data-x-internal=concept-element-local-name>local
      name</a>.</p>

      <p class=note>This ensure that only container-initiated navigations are reported to
      resource timing.</p>
     </ol>
   <li><p>Let <var>response</var> be null.<li><p>Let <var>responseOrigin</var> be null.<li><p>Let <var>fetchController</var> be null.<li>
    <p>Let <var>coopEnforcementResult</var> be a new <a href=browsers.html#coop-enforcement-result id=populating-a-session-history-entry:coop-enforcement-result-2>opener
    policy enforcement result</a>, with</p>

    <dl class=props><dt><a href=browsers.html#coop-enforcement-url id=populating-a-session-history-entry:coop-enforcement-url-2>url</a><dd><var>navigable</var>'s <a href=document-sequences.html#nav-document id=populating-a-session-history-entry:nav-document-3>active document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-url id="populating-a-session-history-entry:the-document's-address-2" data-x-internal="the-document's-address">URL</a><dt><a href=browsers.html#coop-enforcement-origin id=populating-a-session-history-entry:coop-enforcement-origin-2>origin</a><dd><var>navigable</var>'s <a href=document-sequences.html#nav-document id=populating-a-session-history-entry:nav-document-4>active document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=populating-a-session-history-entry:concept-document-origin-2 data-x-internal=concept-document-origin>origin</a><dt><a href=browsers.html#coop-enforcement-coop id=populating-a-session-history-entry:coop-enforcement-coop-2>opener policy</a><dd><var>navigable</var>'s <a href=document-sequences.html#nav-document id=populating-a-session-history-entry:nav-document-5>active document</a>'s <a href=dom.html#concept-document-coop id=populating-a-session-history-entry:concept-document-coop>opener policy</a><dt><a href=browsers.html#coop-enforcement-source id=populating-a-session-history-entry:coop-enforcement-source>current context is navigation source</a><dd>true if <var>navigable</var>'s <a href=document-sequences.html#nav-document id=populating-a-session-history-entry:nav-document-6>active document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=populating-a-session-history-entry:concept-document-origin-3 data-x-internal=concept-document-origin>origin</a> is <a id=populating-a-session-history-entry:same-origin href=browsers.html#same-origin>same origin</a> with
     <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-29>document state</a>'s <a href=#document-state-initiator-origin id=populating-a-session-history-entry:document-state-initiator-origin-4>initiator origin</a> otherwise false</dl>
   <li><p>Let <var>finalSandboxFlags</var> be an empty <a id=populating-a-session-history-entry:sandboxing-flag-set href=browsers.html#sandboxing-flag-set>sandboxing flag set</a>.<li><p>Let <var>responsePolicyContainer</var> be null.<li><p>Let <var>responseCOOP</var> be a new <a id=populating-a-session-history-entry:cross-origin-opener-policy-2 href=browsers.html#cross-origin-opener-policy>opener policy</a>.<li><p>Let <var>locationURL</var> be null.<li><p>Let <var>currentURL</var> be <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-current-url id=populating-a-session-history-entry:concept-request-current-url data-x-internal=concept-request-current-url>current URL</a>.<li><p>Let <var>commitEarlyHints</var> be null.<li>
    <p>While true:</p>

    <ol><li>
      <p>If <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-reserved-client id=populating-a-session-history-entry:concept-request-reserved-client data-x-internal=concept-request-reserved-client>reserved
      client</a> is not null and <var>currentURL</var>'s <a href=https://url.spec.whatwg.org/#concept-url-origin id=populating-a-session-history-entry:concept-url-origin data-x-internal=concept-url-origin>origin</a> is not the <a href=browsers.html#same-origin id=populating-a-session-history-entry:same-origin-2>same</a>
      as <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-reserved-client id=populating-a-session-history-entry:concept-request-reserved-client-2 data-x-internal=concept-request-reserved-client>reserved
      client</a>'s <a href=webappapis.html#concept-environment-creation-url id=populating-a-session-history-entry:concept-environment-creation-url>creation URL</a>'s <a href=https://url.spec.whatwg.org/#concept-url-origin id=populating-a-session-history-entry:concept-url-origin-2 data-x-internal=concept-url-origin>origin</a>, then:</p>

      <ol><li><p>Run the <a id=populating-a-session-history-entry:environment-discarding-steps-2 href=webappapis.html#environment-discarding-steps>environment discarding steps</a> for <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-reserved-client id=populating-a-session-history-entry:concept-request-reserved-client-3 data-x-internal=concept-request-reserved-client>reserved client</a>.<li><p>Set <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-reserved-client id=populating-a-session-history-entry:concept-request-reserved-client-4 data-x-internal=concept-request-reserved-client>reserved
       client</a> to null.<li>
        <p>Set <var>commitEarlyHints</var> to null.</p>

        <p class=note>Preloaded links from <a href=semantics.html#early-hints-2 id=populating-a-session-history-entry:early-hints-2>early hint headers</a>
        remain in the preload cache after a <a id=populating-a-session-history-entry:same-origin-3 href=browsers.html#same-origin>same origin</a> redirect, but get discarded
        when the redirect is cross-origin.</p>
       </ol>
     <li>
      <p>If <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-reserved-client id=populating-a-session-history-entry:concept-request-reserved-client-5 data-x-internal=concept-request-reserved-client>reserved
      client</a> is null, then:</p>

      <ol><li><p>Let <var>topLevelCreationURL</var> be <var>currentURL</var>.<li><p>Let <var>topLevelOrigin</var> be null.<li>
        <p>If <var>navigable</var> is not a <a id=populating-a-session-history-entry:top-level-traversable-2 href=document-sequences.html#top-level-traversable>top-level traversable</a>, then:</p>

        <ol><li><p>Let <var>parentEnvironment</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-parent id=populating-a-session-history-entry:nav-parent>parent</a>'s <a href=document-sequences.html#nav-document id=populating-a-session-history-entry:nav-document-7>active document</a>'s
         <a id=populating-a-session-history-entry:relevant-settings-object-3 href=webappapis.html#relevant-settings-object>relevant settings object</a>.<li><p>Set <var>topLevelCreationURL</var> to <var>parentEnvironment</var>'s
         <a id=populating-a-session-history-entry:concept-environment-top-level-creation-url href=webappapis.html#concept-environment-top-level-creation-url>top-level creation URL</a>.<li><p>Set <var>topLevelOrigin</var> to <var>parentEnvironment</var>'s <a id=populating-a-session-history-entry:concept-environment-top-level-origin href=webappapis.html#concept-environment-top-level-origin>top-level
         origin</a>.</ol>
       <li>
        <p>Set <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-reserved-client id=populating-a-session-history-entry:concept-request-reserved-client-6 data-x-internal=concept-request-reserved-client>reserved
        client</a> to a new <a id=populating-a-session-history-entry:environment href=webappapis.html#environment>environment</a> whose <a href=webappapis.html#concept-environment-id id=populating-a-session-history-entry:concept-environment-id-2>id</a> is a unique opaque string, <a href=webappapis.html#concept-environment-target-browsing-context id=populating-a-session-history-entry:concept-environment-target-browsing-context>target browsing context</a> is
        <var>navigable</var>'s <a href=document-sequences.html#nav-bc id=populating-a-session-history-entry:nav-bc>active browsing context</a>, <a href=webappapis.html#concept-environment-creation-url id=populating-a-session-history-entry:concept-environment-creation-url-2>creation URL</a> is <var>currentURL</var>,
        <a id=populating-a-session-history-entry:concept-environment-top-level-creation-url-2 href=webappapis.html#concept-environment-top-level-creation-url>top-level creation URL</a> is <var>topLevelCreationURL</var>, and <a id=populating-a-session-history-entry:concept-environment-top-level-origin-2 href=webappapis.html#concept-environment-top-level-origin>top-level
        origin</a> is <var>topLevelOrigin</var>.</p>

        <p class=note>The created environment's <a href=webappapis.html#concept-environment-active-service-worker id=populating-a-session-history-entry:concept-environment-active-service-worker>active service worker</a> is set in
        the <a href=https://w3c.github.io/ServiceWorker/#on-fetch-request-algorithm id=populating-a-session-history-entry:on-fetch-request-algorithm data-x-internal=on-fetch-request-algorithm>Handle Fetch</a> algorithm during the fetch
        if the request URL matches a service worker registration. <a href=references.html#refsSW>[SW]</a></p>
       </ol>
     <li><p>If the result of <a id=populating-a-session-history-entry:should-navigation-request-of-type-be-blocked-by-content-security-policy href=https://w3c.github.io/webappsec-csp/#should-block-navigation-request data-x-internal=should-navigation-request-of-type-be-blocked-by-content-security-policy>should navigation request of type be blocked by Content Security
     Policy?</a> given <var>request</var> and <var>cspNavigationType</var> is "<code>Blocked</code>", then set <var>response</var> to a <a id=populating-a-session-history-entry:network-error href=https://fetch.spec.whatwg.org/#concept-network-error data-x-internal=network-error>network error</a> and
     <a id=populating-a-session-history-entry:break href=https://infra.spec.whatwg.org/#iteration-break data-x-internal=break>break</a>. <a href=references.html#refsCSP>[CSP]</a><li><p>Set <var>response</var> to null.<li>
      <p>If <var>fetchController</var> is null, then set <var>fetchController</var> to the result
      of <a href=https://fetch.spec.whatwg.org/#concept-fetch id=populating-a-session-history-entry:concept-fetch data-x-internal=concept-fetch>fetching</a> <var>request</var>, with <i id=populating-a-session-history-entry:processearlyhintsresponse><a data-x-internal=processearlyhintsresponse href=https://fetch.spec.whatwg.org/#fetch-processearlyhintsresponse>processEarlyHintsResponse</a></i> set to
      <var>processEarlyHintsResponse</var> as defined below, <i id=populating-a-session-history-entry:processresponse><a data-x-internal=processresponse href=https://fetch.spec.whatwg.org/#process-response>processResponse</a></i> set to <var>processResponse</var> as defined
      below, and <i id=populating-a-session-history-entry:useparallelqueue><a data-x-internal=useparallelqueue href=https://fetch.spec.whatwg.org/#fetch-useparallelqueue>useParallelQueue</a></i> set to true.</p>

      <p>Let <var>processEarlyHintsResponse</var> be the following algorithm given a <a href=https://fetch.spec.whatwg.org/#concept-response id=populating-a-session-history-entry:concept-response-2 data-x-internal=concept-response>response</a> <var>earlyResponse</var>:</p>

      <ol><li><p>If <var>commitEarlyHints</var> is null, then set <var>commitEarlyHints</var> to the
       result of <a href=semantics.html#process-early-hint-headers id=populating-a-session-history-entry:process-early-hint-headers>processing early hint headers</a>
       given <var>earlyResponse</var> and <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-reserved-client id=populating-a-session-history-entry:concept-request-reserved-client-7 data-x-internal=concept-request-reserved-client>reserved client</a>.</ol>

      <p>Let <var>processResponse</var> be the following algorithm given a <a href=https://fetch.spec.whatwg.org/#concept-response id=populating-a-session-history-entry:concept-response-3 data-x-internal=concept-response>response</a> <var>fetchedResponse</var>:</p>

      <ol><li><p>Set <var>response</var> to <var>fetchedResponse</var>.</ol>
     <li>
      <p>Otherwise, <a id=populating-a-session-history-entry:process-the-next-manual-redirect href=https://fetch.spec.whatwg.org/#fetch-controller-process-the-next-manual-redirect data-x-internal=process-the-next-manual-redirect>process the next manual redirect</a> for
      <var>fetchController</var>.</p>

      <p class=note>This will result in calling the <i id=populating-a-session-history-entry:processresponse-2><a data-x-internal=processresponse href=https://fetch.spec.whatwg.org/#process-response>processResponse</a></i> we supplied above, during our first iteration
      through the loop, and thus setting <var>response</var>.</p>

      <p class=note>Navigation handles redirects manually as navigation is the only place in the
      web platform that cares for redirects to <code id=populating-a-session-history-entry:mailto-protocol><a data-x-internal=mailto-protocol href=https://www.rfc-editor.org/rfc/rfc6068#section-2>mailto:</a></code> URLs
      and such.</p>
     <li>
      <p>Wait until either <var>response</var> is non-null, or <var>navigable</var>'s <a href=#ongoing-navigation id=populating-a-session-history-entry:ongoing-navigation-2>ongoing
      navigation</a> changes to no longer equal <var>navigationId</var>.</p>

      <p>If the latter condition occurs, then <a href=https://fetch.spec.whatwg.org/#fetch-controller-abort id=populating-a-session-history-entry:fetch-controller-abort data-x-internal=fetch-controller-abort>abort</a>
      <var>fetchController</var>, and return.</p>

      <p>Otherwise, proceed onward.</p>
     <li>
      <p>If <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-body id=populating-a-session-history-entry:concept-request-body-2 data-x-internal=concept-request-body>body</a> is null, then set
      <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-30>document state</a>'s <a href=#document-state-resource id=populating-a-session-history-entry:document-state-resource-5>resource</a> to null.</p>

      <p class=note>Fetch unsets the <a href=https://fetch.spec.whatwg.org/#concept-request-body id=populating-a-session-history-entry:concept-request-body-3 data-x-internal=concept-request-body>body</a> for
      particular redirects.</p>
     <li><p>Set <var>responsePolicyContainer</var> to the result of <a id=populating-a-session-history-entry:creating-a-policy-container-from-a-fetch-response href=browsers.html#creating-a-policy-container-from-a-fetch-response>creating a policy
     container from a fetch response</a> given <var>response</var> and <var>request</var>'s
     <a href=https://fetch.spec.whatwg.org/#concept-request-reserved-client id=populating-a-session-history-entry:concept-request-reserved-client-8 data-x-internal=concept-request-reserved-client>reserved client</a>.<li><p>Set <var>finalSandboxFlags</var> to the <a href=https://infra.spec.whatwg.org/#set-union id=populating-a-session-history-entry:set-union data-x-internal=set-union>union</a> of
     <var>targetSnapshotParams</var>'s <a href=#target-snapshot-params-sandbox id=populating-a-session-history-entry:target-snapshot-params-sandbox-4>sandboxing
     flags</a> and <var>responsePolicyContainer</var>'s <a href=browsers.html#policy-container-csp-list id=populating-a-session-history-entry:policy-container-csp-list-3>CSP list</a>'s <a id=populating-a-session-history-entry:csp-derived-sandboxing-flags href=browsers.html#csp-derived-sandboxing-flags>CSP-derived sandboxing
     flags</a>.<li>
      <p>Set <var>responseOrigin</var> to the result of <a id=populating-a-session-history-entry:determining-the-origin-2 href=document-sequences.html#determining-the-origin>determining the origin</a> given
      <var>response</var>'s <a href=https://fetch.spec.whatwg.org/#concept-response-url id=populating-a-session-history-entry:concept-response-url-7 data-x-internal=concept-response-url>URL</a>,
      <var>finalSandboxFlags</var>, and <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-31>document state</a>'s <a href=#document-state-initiator-origin id=populating-a-session-history-entry:document-state-initiator-origin-5>initiator origin</a>.</p>

      <p class=note>If <var>response</var> is a redirect, then <var>response</var>'s <a href=https://fetch.spec.whatwg.org/#concept-response-url id=populating-a-session-history-entry:concept-response-url-8 data-x-internal=concept-response-url>URL</a> will be the URL that led to the redirect to
      <var>response</var>'s <a href=https://fetch.spec.whatwg.org/#concept-response-location-url id=populating-a-session-history-entry:concept-response-location-url data-x-internal=concept-response-location-url>location URL</a>; it
      will not be the <a href=https://fetch.spec.whatwg.org/#concept-response-location-url id=populating-a-session-history-entry:concept-response-location-url-2 data-x-internal=concept-response-location-url>location URL</a> itself.</p>
     <li>
      <p>If <var>navigable</var> is a <a id=populating-a-session-history-entry:top-level-traversable-3 href=document-sequences.html#top-level-traversable>top-level traversable</a>, then:</p>

      <ol><li><p>Set <var>responseCOOP</var> to the result of <a href=browsers.html#obtain-coop id=populating-a-session-history-entry:obtain-coop>obtaining an
       opener policy</a> given <var>response</var> and <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-reserved-client id=populating-a-session-history-entry:concept-request-reserved-client-9 data-x-internal=concept-request-reserved-client>reserved client</a>.<li><p>Set <var>coopEnforcementResult</var> to the result of <a href=browsers.html#coop-enforce id=populating-a-session-history-entry:coop-enforce>enforcing the response's opener policy</a> given
       <var>navigable</var>'s <a href=document-sequences.html#nav-bc id=populating-a-session-history-entry:nav-bc-2>active browsing context</a>,
       <var>response</var>'s <a href=https://fetch.spec.whatwg.org/#concept-response-url id=populating-a-session-history-entry:concept-response-url-9 data-x-internal=concept-response-url>URL</a>,
       <var>responseOrigin</var>, <var>responseCOOP</var>, <var>coopEnforcementResult</var>, and
       <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-referrer id=populating-a-session-history-entry:concept-request-referrer-4 data-x-internal=concept-request-referrer>referrer</a>.<li>
        <p>If <var>finalSandboxFlags</var> is not empty and <var>responseCOOP</var>'s <a href=browsers.html#coop-struct-value id=populating-a-session-history-entry:coop-struct-value>value</a> is not "<code id=populating-a-session-history-entry:coop-unsafe-none><a href=browsers.html#coop-unsafe-none>unsafe-none</a></code>", then set <var>response</var> to an
        appropriate <a id=populating-a-session-history-entry:network-error-2 href=https://fetch.spec.whatwg.org/#concept-network-error data-x-internal=network-error>network error</a> and <a id=populating-a-session-history-entry:break-2 href=https://infra.spec.whatwg.org/#iteration-break data-x-internal=break>break</a>.</p>

        <p class=note>This results in a network error as one cannot simultaneously provide a clean
        slate to a response using opener policy and sandbox the result of
        navigating to that response.</p>
       </ol>
     <li>
      <p>If <var>response</var> is not a <a id=populating-a-session-history-entry:network-error-3 href=https://fetch.spec.whatwg.org/#concept-network-error data-x-internal=network-error>network error</a>, <var>navigable</var> is a
      <a id=populating-a-session-history-entry:child-navigable href=document-sequences.html#child-navigable>child navigable</a>, and the result of performing a <a id=populating-a-session-history-entry:cross-origin-resource-policy-check href=https://fetch.spec.whatwg.org/#cross-origin-resource-policy-check data-x-internal=cross-origin-resource-policy-check>cross-origin resource
      policy check</a> with <var>navigable</var>'s <a href=document-sequences.html#nav-container-document id=populating-a-session-history-entry:nav-container-document-3>container document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=populating-a-session-history-entry:concept-document-origin-4 data-x-internal=concept-document-origin>origin</a>, <var>navigable</var>'s <a href=document-sequences.html#nav-container-document id=populating-a-session-history-entry:nav-container-document-4>container document</a>'s <a id=populating-a-session-history-entry:relevant-settings-object-4 href=webappapis.html#relevant-settings-object>relevant settings
      object</a>, <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-destination id=populating-a-session-history-entry:concept-request-destination-3 data-x-internal=concept-request-destination>destination</a>, <var>response</var>, and true is
      <b>blocked</b>, then set <var>response</var> to a <a id=populating-a-session-history-entry:network-error-4 href=https://fetch.spec.whatwg.org/#concept-network-error data-x-internal=network-error>network error</a> and
      <a id=populating-a-session-history-entry:break-3 href=https://infra.spec.whatwg.org/#iteration-break data-x-internal=break>break</a>.</p>

      <p class=note>Here we're running the <a id=populating-a-session-history-entry:cross-origin-resource-policy-check-2 href=https://fetch.spec.whatwg.org/#cross-origin-resource-policy-check data-x-internal=cross-origin-resource-policy-check>cross-origin resource policy check</a>
      against the <a href=document-sequences.html#nav-parent id=populating-a-session-history-entry:nav-parent-2>parent navigable</a> rather than
      <var>navigable</var> itself. This is because we care about the same-originness of the
      embedded content against the parent context, not the navigation source.</p>
     <li><p>Set <var>locationURL</var> to <var>response</var>'s <a href=https://fetch.spec.whatwg.org/#concept-response-location-url id=populating-a-session-history-entry:concept-response-location-url-3 data-x-internal=concept-response-location-url>location URL</a> given <var>currentURL</var>'s <a href=https://url.spec.whatwg.org/#concept-url-fragment id=populating-a-session-history-entry:concept-url-fragment data-x-internal=concept-url-fragment>fragment</a>.<li><p>If <var>locationURL</var> is failure or null, then <a id=populating-a-session-history-entry:break-4 href=https://infra.spec.whatwg.org/#iteration-break data-x-internal=break>break</a>.<li><p><a id=populating-a-session-history-entry:assert-6 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>locationURL</var> is a <a id=populating-a-session-history-entry:url href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a>.<li><p>Set <var>entry</var>'s <a href=#she-classic-history-api-state id=populating-a-session-history-entry:she-classic-history-api-state>classic history API
     state</a> to <a id=populating-a-session-history-entry:structuredserializeforstorage href=structured-data.html#structuredserializeforstorage>StructuredSerializeForStorage</a>(null).<li><p>Let <var>oldDocState</var> be <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-32>document state</a>.<li>
      <p>Set <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-33>document state</a> to a new
      <a href=#document-state-2 id=populating-a-session-history-entry:document-state-2>document state</a>, with

      <dl class=props><dt><a href=#document-state-history-policy-container id=populating-a-session-history-entry:document-state-history-policy-container-3>history policy container</a><dd>a <a href=browsers.html#clone-a-policy-container id=populating-a-session-history-entry:clone-a-policy-container>clone</a> of the <var>oldDocState</var>'s
       <a href=#document-state-history-policy-container id=populating-a-session-history-entry:document-state-history-policy-container-4>history policy container</a> if it
       is non-null; null otherwise<dt><a href=#document-state-request-referrer id=populating-a-session-history-entry:document-state-request-referrer-4>request referrer</a><dd><var>oldDocState</var>'s <a href=#document-state-request-referrer id=populating-a-session-history-entry:document-state-request-referrer-5>request
       referrer</a><dt><a href=#document-state-request-referrer-policy id=populating-a-session-history-entry:document-state-request-referrer-policy-2>request referrer policy</a><dd><var>oldDocState</var>'s <a href=#document-state-request-referrer-policy id=populating-a-session-history-entry:document-state-request-referrer-policy-3>request
       referrer policy</a><dt><a href=#document-state-initiator-origin id=populating-a-session-history-entry:document-state-initiator-origin-6>initiator origin</a><dd><var>oldDocState</var>'s <a href=#document-state-initiator-origin id=populating-a-session-history-entry:document-state-initiator-origin-7>initiator
       origin</a><dt><a href=#document-state-origin id=populating-a-session-history-entry:document-state-origin-3>origin</a><dd><var>oldDocState</var>'s <a href=#document-state-origin id=populating-a-session-history-entry:document-state-origin-4>origin</a><dt><a href=#document-state-about-base-url id=populating-a-session-history-entry:document-state-about-base-url-2>about base URL</a><dd><var>oldDocState</var>'s <a href=#document-state-about-base-url id=populating-a-session-history-entry:document-state-about-base-url-3>about base URL</a><dt><a href=#document-state-resource id=populating-a-session-history-entry:document-state-resource-6>resource</a><dd><var>oldDocState</var>'s <a href=#document-state-resource id=populating-a-session-history-entry:document-state-resource-7>resource</a><dt><a href=#document-state-ever-populated id=populating-a-session-history-entry:document-state-ever-populated-3>ever populated</a><dd><var>oldDocState</var>'s <a href=#document-state-ever-populated id=populating-a-session-history-entry:document-state-ever-populated-4>ever
       populated</a><dt><a href=#document-state-nav-target-name id=populating-a-session-history-entry:document-state-nav-target-name>navigable target name</a><dd><var>oldDocState</var>'s <a href=#document-state-nav-target-name id=populating-a-session-history-entry:document-state-nav-target-name-2>navigable target
       name</a></dl>

      
      <p class=note>For the navigation case, only <var>entry</var> referenced
      <var>oldDocState</var>, which was created <a href=#navigation-create-document-state>early
      in the navigate algorithm</a>. So for navigations, this is functionally just an update to
      <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-34>document state</a>. For the traversal
      case, it's possible adjacent <a href=#session-history-entry id=populating-a-session-history-entry:session-history-entry-7>session history
      entries</a> also reference <var>oldDocState</var>, in which case they will continue doing
      so even after we've updated <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-35>document
      state</a>.</p>

      <p class=note><var>oldDocState</var>'s <a href=#document-state-history-policy-container id=populating-a-session-history-entry:document-state-history-policy-container-5>history policy container</a> is only ever
      non-null here in the traversal case, after we've populated it during a navigation to a URL
      that <a id=populating-a-session-history-entry:requires-storing-the-policy-container-in-history-2 href=browsers.html#requires-storing-the-policy-container-in-history>requires storing the policy container in history</a>.</p>

      <div class=example>
       <p>The setup is given by the following <a id=populating-a-session-history-entry:jake-diagram href=document-sequences.html#jake-diagram>Jake diagram</a>:</p>

       
<table class=jake-diagram><thead><tr><td><th class=step>0<th class=step>1<th class=step>2<th class="step current">3<tbody><tr><th><code>top</code><td colspan=1 class="doc-0 next-is-same-doc">/a<td colspan=1 class="doc-0 prev-is-same-doc next-is-same-doc">/a#foo<td colspan=1 class="doc-0 prev-is-same-doc">/a#bar<td colspan=1 class="doc-2 current">/b</table>

       <p>Also assume that the <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-36>document state</a> shared by
       the entries in steps 0, 1, and 2 has a null <a href=#document-state-document id=populating-a-session-history-entry:document-state-document-12>document</a>, i.e., <a href=#note-bfcache>bfcache</a>
       is not in play.</p>

       <p>Now consider the scenario where we traverse back to step 2, but this time when fetching
       <code>/a</code>, the server responds with a `<code>Location</code>`
       header pointing to <code>/c</code>. That is, <var>locationURL</var> points to
       <code>/c</code> and so we have reached this step instead of <a href=https://infra.spec.whatwg.org/#iteration-break id=populating-a-session-history-entry:break-5 data-x-internal=break>breaking</a> out of the loop.</p>

       <p>In this case, we replace the <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-37>document state</a> of
       the <a href=#session-history-entry id=populating-a-session-history-entry:session-history-entry-8>session history entry</a> occupying step 2, but we do <em>not</em> replace the
       document state of the entries occupying steps 0 and 1. The resulting <a id=populating-a-session-history-entry:jake-diagram-2 href=document-sequences.html#jake-diagram>Jake
       diagram</a> looks like this:</p>

       
<table class=jake-diagram><thead><tr><td><th class=step>0<th class=step>1<th class="step current">2<th class=step>3<tbody><tr><th><code>top</code><td colspan=1 class="doc-0 next-is-same-doc">/a<td colspan=1 class="doc-0 prev-is-same-doc">/a#foo<td colspan=1 class="doc-1 current">/c#bar<td colspan=1 class=doc-2>/b</table>

       <p>Note that we perform this replacement even if we end up in a redirect chain back to the
       original URL, for example if <code>/c</code> itself had a `<code>Location</code>` header pointing to <code>/a</code>. Such a case would
       end up like so:</p>

       
<table class=jake-diagram><thead><tr><td><th class=step>0<th class=step>1<th class="step current">2<th class=step>3<tbody><tr><th><code>top</code><td colspan=1 class="doc-0 next-is-same-doc">/a<td colspan=1 class="doc-0 prev-is-same-doc">/a#foo<td colspan=1 class="doc-1 current">/a#bar<td colspan=1 class=doc-2>/b</table>
      </div>
     <li>
      <p>If <var>locationURL</var>'s <a href=https://url.spec.whatwg.org/#concept-url-scheme id=populating-a-session-history-entry:concept-url-scheme-3 data-x-internal=concept-url-scheme>scheme</a> is not an
      <a id=populating-a-session-history-entry:http(s)-scheme href=https://fetch.spec.whatwg.org/#http-scheme data-x-internal=http(s)-scheme>HTTP(S) scheme</a>, then:</p>

      <ol><li><p>Set <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-38>document state</a>'s
       <a href=#document-state-resource id=populating-a-session-history-entry:document-state-resource-8>resource</a> to null.<li><p><a id=populating-a-session-history-entry:break-6 href=https://infra.spec.whatwg.org/#iteration-break data-x-internal=break>Break</a>.</ol>
     <li><p>Set <var>currentURL</var> to <var>locationURL</var>.<li><p>Set <var>entry</var>'s <a href=#she-url id=populating-a-session-history-entry:she-url-5>URL</a> to
     <var>currentURL</var>.</ol>

    <div class=note>
     <p>By the end of this loop we will be in one of these scenarios:</p>

     <ul><li><p><var>locationURL</var> is failure, because of an unparseable `<code>Location</code>` header.<li><p><var>locationURL</var> is null, either because <var>response</var> is a <a id=populating-a-session-history-entry:network-error-5 href=https://fetch.spec.whatwg.org/#concept-network-error data-x-internal=network-error>network
      error</a> or because we successfully fetched a non-<a id=populating-a-session-history-entry:network-error-6 href=https://fetch.spec.whatwg.org/#concept-network-error data-x-internal=network-error>network error</a> HTTP(S)
      response with no `<code>Location</code>` header.<li><p><var>locationURL</var> is a <a id=populating-a-session-history-entry:url-2 href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> with a non-<a href=https://fetch.spec.whatwg.org/#http-scheme id=populating-a-session-history-entry:http(s)-scheme-2 data-x-internal=http(s)-scheme>HTTP(S)</a> <a href=https://url.spec.whatwg.org/#concept-url-scheme id=populating-a-session-history-entry:concept-url-scheme-4 data-x-internal=concept-url-scheme>scheme</a>.</ul>
    </div>
   <li>
    <p>If <var>locationURL</var> is a <a id=populating-a-session-history-entry:url-3 href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> whose <a href=https://url.spec.whatwg.org/#concept-url-scheme id=populating-a-session-history-entry:concept-url-scheme-5 data-x-internal=concept-url-scheme>scheme</a> is not a <a id=populating-a-session-history-entry:fetch-scheme-3 href=https://fetch.spec.whatwg.org/#fetch-scheme data-x-internal=fetch-scheme>fetch scheme</a>, then return a new
    <a href=#non-fetch-scheme-navigation-params id=populating-a-session-history-entry:non-fetch-scheme-navigation-params-6>non-fetch scheme navigation params</a>, with</p>

    <dl class=props><dt><a href=#non-fetch-scheme-params-id id=populating-a-session-history-entry:non-fetch-scheme-params-id-2>id</a><dd><var>navigationId</var><dt><a href=#non-fetch-scheme-params-navigable id=populating-a-session-history-entry:non-fetch-scheme-params-navigable-2>navigable</a><dd><var>navigable</var><dt><a href=#non-fetch-scheme-params-url id=populating-a-session-history-entry:non-fetch-scheme-params-url-2>URL</a><dd><var>locationURL</var><dt><a href=#non-fetch-scheme-params-target-sandbox id=populating-a-session-history-entry:non-fetch-scheme-params-target-sandbox-2>target snapshot sandboxing flags</a><dd><var>targetSnapshotParams</var>'s <a href=#target-snapshot-params-sandbox id=populating-a-session-history-entry:target-snapshot-params-sandbox-5>sandboxing
     flags</a><dt><a href=#non-fetch-scheme-params-source-activation id=populating-a-session-history-entry:non-fetch-scheme-params-source-activation-2>source snapshot has transient activation</a><dd><var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-activation id=populating-a-session-history-entry:source-snapshot-params-activation-3>has
     transient activation</a><dt><a href=#non-fetch-scheme-params-initiator-origin id=populating-a-session-history-entry:non-fetch-scheme-params-initiator-origin-2>initiator origin</a><dd><var>responseOrigin</var><dt><a href=#non-fetch-scheme-params-nav-timing-type id=populating-a-session-history-entry:non-fetch-scheme-params-nav-timing-type-2>navigation timing type</a><dd><var>navTimingType</var><dt><a href=#non-fetch-scheme-params-user-involvement id=populating-a-session-history-entry:non-fetch-scheme-params-user-involvement-2>user involvement</a><dd><var>userInvolvement</var></dl>

    <p class=note>At this point, <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-current-url id=populating-a-session-history-entry:concept-request-current-url-2 data-x-internal=concept-request-current-url>current URL</a> is the last <a id=populating-a-session-history-entry:url-4 href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> in the
    redirect chain with a <a href=https://fetch.spec.whatwg.org/#fetch-scheme id=populating-a-session-history-entry:fetch-scheme-4 data-x-internal=fetch-scheme>fetch</a> <a href=https://url.spec.whatwg.org/#concept-url-scheme id=populating-a-session-history-entry:concept-url-scheme-6 data-x-internal=concept-url-scheme>scheme</a> before redirecting to a non-<a id=populating-a-session-history-entry:fetch-scheme-5 href=https://fetch.spec.whatwg.org/#fetch-scheme data-x-internal=fetch-scheme>fetch scheme</a>
    <a id=populating-a-session-history-entry:url-5 href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a>. It is this <a id=populating-a-session-history-entry:url-6 href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a>'s <a href=https://url.spec.whatwg.org/#concept-url-origin id=populating-a-session-history-entry:concept-url-origin-3 data-x-internal=concept-url-origin>origin</a>
    that will be used as the initiator origin for navigations to non-<a id=populating-a-session-history-entry:fetch-scheme-6 href=https://fetch.spec.whatwg.org/#fetch-scheme data-x-internal=fetch-scheme>fetch scheme</a>
    <a href=https://url.spec.whatwg.org/#concept-url id=populating-a-session-history-entry:url-7 data-x-internal=url>URLs</a>.</p>
   <li>
    <p>If any of the following are true:</p>

    <ul><li><p><var>response</var> is a <a id=populating-a-session-history-entry:network-error-7 href=https://fetch.spec.whatwg.org/#concept-network-error data-x-internal=network-error>network error</a>;<li><p><var>locationURL</var> is failure; or<li><p><var>locationURL</var> is a <a id=populating-a-session-history-entry:url-8 href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> whose <a href=https://url.spec.whatwg.org/#concept-url-scheme id=populating-a-session-history-entry:concept-url-scheme-7 data-x-internal=concept-url-scheme>scheme</a> is a <a id=populating-a-session-history-entry:fetch-scheme-7 href=https://fetch.spec.whatwg.org/#fetch-scheme data-x-internal=fetch-scheme>fetch scheme</a>,</ul>

    <p>then return null.</p>

    <p class=note>We allow redirects to non-<a id=populating-a-session-history-entry:fetch-scheme-8 href=https://fetch.spec.whatwg.org/#fetch-scheme data-x-internal=fetch-scheme>fetch scheme</a> <a href=https://url.spec.whatwg.org/#concept-url id=populating-a-session-history-entry:url-9 data-x-internal=url>URLs</a>, but redirects to <a id=populating-a-session-history-entry:fetch-scheme-9 href=https://fetch.spec.whatwg.org/#fetch-scheme data-x-internal=fetch-scheme>fetch scheme</a> <a href=https://url.spec.whatwg.org/#concept-url id=populating-a-session-history-entry:url-10 data-x-internal=url>URLs</a> that aren't <a href=https://fetch.spec.whatwg.org/#http-scheme id=populating-a-session-history-entry:http(s)-scheme-3 data-x-internal=http(s)-scheme>HTTP(S)</a> are treated
    like network errors.</p>
   <li><p><a id=populating-a-session-history-entry:assert-7 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>locationURL</var> is null and <var>response</var> is not a
   <a id=populating-a-session-history-entry:network-error-8 href=https://fetch.spec.whatwg.org/#concept-network-error data-x-internal=network-error>network error</a>.<li><p>Let <var>resultPolicyContainer</var> be the result of <a id=populating-a-session-history-entry:determining-navigation-params-policy-container-2 href=browsers.html#determining-navigation-params-policy-container>determining navigation params
   policy container</a> given <var>response</var>'s <a href=https://fetch.spec.whatwg.org/#concept-response-url id=populating-a-session-history-entry:concept-response-url-10 data-x-internal=concept-response-url>URL</a>, <var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-39>document state</a>'s <a href=#document-state-history-policy-container id=populating-a-session-history-entry:document-state-history-policy-container-6>history policy container</a>,
   <var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-policy-container id=populating-a-session-history-entry:source-snapshot-params-policy-container-2>source
   policy container</a>, null, and <var>responsePolicyContainer</var>.<li>
    <p>If <var>navigable</var>'s <a href=document-sequences.html#nav-container id=populating-a-session-history-entry:nav-container-6>container</a> is an
    <code id=populating-a-session-history-entry:the-iframe-element><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code>, and <var>response</var>'s <a href=https://fetch.spec.whatwg.org/#concept-response-timing-allow-passed id=populating-a-session-history-entry:concept-response-timing-allow-passed data-x-internal=concept-response-timing-allow-passed>timing allow passed flag</a> is set, then
    set <var>navigable</var>'s <a href=document-sequences.html#nav-container id=populating-a-session-history-entry:nav-container-7>container</a>'s <a href=iframe-embed-object.html#iframe-pending-resource-timing-start-time id=populating-a-session-history-entry:iframe-pending-resource-timing-start-time>pending resource-timing start time</a> to
    null.</p>

    <p class=note>If the <code id=populating-a-session-history-entry:the-iframe-element-2><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code> is allowed to report to resource timing,
    we don't need to run its fallback steps as the normal reporting would happen.</p>
   <li>
    <p>Return a new <a href=#navigation-params id=populating-a-session-history-entry:navigation-params-6>navigation params</a>, with</p>

    <dl class=props><dt><a href=#navigation-params-id id=populating-a-session-history-entry:navigation-params-id-2>id</a><dd><var>navigationId</var><dt><a href=#navigation-params-navigable id=populating-a-session-history-entry:navigation-params-navigable-2>navigable</a><dd><var>navigable</var><dt><a href=#navigation-params-request id=populating-a-session-history-entry:navigation-params-request-5>request</a><dd><var>request</var><dt><a href=#navigation-params-response id=populating-a-session-history-entry:navigation-params-response-11>response</a><dd><var>response</var><dt><a href=#navigation-params-fetch-controller id=populating-a-session-history-entry:navigation-params-fetch-controller-2>fetch controller</a><dd><var>fetchController</var><dt><a href=#navigation-params-commit-early-hints id=populating-a-session-history-entry:navigation-params-commit-early-hints-2>commit early hints</a><dd><var>commitEarlyHints</var><dt><a href=#navigation-params-coop id=populating-a-session-history-entry:navigation-params-coop-2>opener policy</a><dd><var>responseCOOP</var><dt><a href=#navigation-params-reserved-environment id=populating-a-session-history-entry:navigation-params-reserved-environment-4>reserved environment</a><dd><var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-reserved-client id=populating-a-session-history-entry:concept-request-reserved-client-10 data-x-internal=concept-request-reserved-client>reserved client</a><dt><a href=#navigation-params-origin id=populating-a-session-history-entry:navigation-params-origin-3>origin</a><dd><var>responseOrigin</var><dt><a href=#navigation-params-policy-container id=populating-a-session-history-entry:navigation-params-policy-container-6>policy container</a><dd><var>resultPolicyContainer</var><dt><a href=#navigation-params-sandboxing id=populating-a-session-history-entry:navigation-params-sandboxing-3>final sandboxing flag set</a><dd><var>finalSandboxFlags</var><dt><a href=#navigation-params-coop-enforcement-result id=populating-a-session-history-entry:navigation-params-coop-enforcement-result-2>COOP enforcement result</a><dd><var>coopEnforcementResult</var><dt><a href=#navigation-params-nav-timing-type id=populating-a-session-history-entry:navigation-params-nav-timing-type-2>navigation timing type</a><dd><var>navTimingType</var><dt><a href=#navigation-params-about-base-url id=populating-a-session-history-entry:navigation-params-about-base-url-2>about base URL</a><dd><var>entry</var>'s <a href=#she-document-state id=populating-a-session-history-entry:she-document-state-40>document state</a>'s <a href=#document-state-about-base-url id=populating-a-session-history-entry:document-state-about-base-url-4>about base URL</a><dt><a href=#navigation-params-user-involvement id=populating-a-session-history-entry:navigation-params-user-involvement-2>user involvement</a><dd><var>userInvolvement</var></dl>
   </ol>

  <p>An element has a <dfn id=browsing-context-scope-origin>browsing context scope origin</dfn> if its <code id=populating-a-session-history-entry:document-4><a href=dom.html#document>Document</a></code>'s
  <a id=populating-a-session-history-entry:node-navigable href=document-sequences.html#node-navigable>node navigable</a> is a <a id=populating-a-session-history-entry:top-level-traversable-4 href=document-sequences.html#top-level-traversable>top-level traversable</a> or if all of its
  <code id=populating-a-session-history-entry:document-5><a href=dom.html#document>Document</a></code>'s <a id=populating-a-session-history-entry:ancestor-navigables href=document-sequences.html#ancestor-navigables>ancestor navigables</a> have <a href=document-sequences.html#nav-document id=populating-a-session-history-entry:nav-document-8>active documents</a> whose <a href=https://dom.spec.whatwg.org/#concept-document-origin id=populating-a-session-history-entry:concept-document-origin-5 data-x-internal=concept-document-origin>origins</a> are the <a id=populating-a-session-history-entry:same-origin-4 href=browsers.html#same-origin>same origin</a> as the element's
  <a id=populating-a-session-history-entry:node-document href=https://dom.spec.whatwg.org/#concept-node-document data-x-internal=node-document>node document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=populating-a-session-history-entry:concept-document-origin-6 data-x-internal=concept-document-origin>origin</a>. If an element
  has a <a href=#browsing-context-scope-origin id=populating-a-session-history-entry:browsing-context-scope-origin-3>browsing context scope origin</a>, then its value is the <a href=https://dom.spec.whatwg.org/#concept-document-origin id=populating-a-session-history-entry:concept-document-origin-7 data-x-internal=concept-document-origin>origin</a> of the element's <a id=populating-a-session-history-entry:node-document-2 href=https://dom.spec.whatwg.org/#concept-node-document data-x-internal=node-document>node document</a>.</p>

  <p class=XXX>This definition is broken and needs investigation to see what it was intended to
  express: see <a href=https://github.com/whatwg/html/issues/4703>issue #4703</a>.</p>

  <p>To <dfn id=loading-a-document>load a document</dfn> given <a href=#navigation-params id=populating-a-session-history-entry:navigation-params-7>navigation params</a>
  <var>navigationParams</var>, <a href=#source-snapshot-params id=populating-a-session-history-entry:source-snapshot-params-3>source snapshot params</a> <var>sourceSnapshotParams</var>,
  and <a id=populating-a-session-history-entry:concept-origin href=browsers.html#concept-origin>origin</a> <var>initiatorOrigin</var>, perform the following steps. They return a
  <code id=populating-a-session-history-entry:document-6><a href=dom.html#document>Document</a></code> or null.</p>

  <ol><li><p>Let <var>type</var> be the <a href=https://mimesniff.spec.whatwg.org/#computed-mime-type id=populating-a-session-history-entry:content-type-sniffing-2 data-x-internal=content-type-sniffing-2>computed type</a> of
   <var>navigationParams</var>'s <a href=#navigation-params-response id=populating-a-session-history-entry:navigation-params-response-12>response</a>.<li>
    <p>If the user agent has been configured to process resources of the given <var>type</var>
    using some mechanism other than rendering the content in a <a id=populating-a-session-history-entry:navigable-6 href=document-sequences.html#navigable>navigable</a>, then
    skip this step. Otherwise, if the <var>type</var> is one of the following types:</p>

    <dl class=switch><dt>an <a id=populating-a-session-history-entry:html-mime-type href=https://mimesniff.spec.whatwg.org/#html-mime-type data-x-internal=html-mime-type>HTML MIME type</a><dd>Return the result of <a href=document-lifecycle.html#navigate-html id=populating-a-session-history-entry:navigate-html>loading an HTML document</a>, given
     <var>navigationParams</var>.<dt>an <a id=populating-a-session-history-entry:xml-mime-type href=https://mimesniff.spec.whatwg.org/#xml-mime-type data-x-internal=xml-mime-type>XML MIME type</a> that is not an <a href=#explicitly-supported-xml-mime-type id=populating-a-session-history-entry:explicitly-supported-xml-mime-type>explicitly supported XML MIME
     type</a><dd>Return the result of <a href=document-lifecycle.html#read-xml id=populating-a-session-history-entry:read-xml>loading an XML document</a> given
     <var>navigationParams</var> and <var>type</var>.<dt>a <a id=populating-a-session-history-entry:javascript-mime-type href=https://mimesniff.spec.whatwg.org/#javascript-mime-type data-x-internal=javascript-mime-type>JavaScript MIME type</a><dt>a <a id=populating-a-session-history-entry:json-mime-type href=https://mimesniff.spec.whatwg.org/#json-mime-type data-x-internal=json-mime-type>JSON MIME type</a> that is not an <a href=#explicitly-supported-json-mime-type id=populating-a-session-history-entry:explicitly-supported-json-mime-type>explicitly supported JSON MIME
     type</a><dt>"<code id=populating-a-session-history-entry:text/css><a href=indices.html#text/css>text/css</a></code>"<dt>"<code id=populating-a-session-history-entry:text/plain><a data-x-internal=text/plain href=https://www.rfc-editor.org/rfc/rfc2046#section-4.1.3>text/plain</a></code>"<dt>"<code id=populating-a-session-history-entry:text/vtt><a href=indices.html#text/vtt>text/vtt</a></code>"<dd>Return the result of <a href=document-lifecycle.html#navigate-text id=populating-a-session-history-entry:navigate-text>loading a text document</a> given
     <var>navigationParams</var> and <var>type</var>.<dt>"<code id=populating-a-session-history-entry:multipart/x-mixed-replace><a href=iana.html#multipart/x-mixed-replace>multipart/x-mixed-replace</a></code>"<dd>Return the result of <a href=document-lifecycle.html#navigate-multipart-x-mixed-replace id=populating-a-session-history-entry:navigate-multipart-x-mixed-replace>loading a
     <code>multipart/x-mixed-replace</code> document</a>, given <var>navigationParams</var>,
     <var>sourceSnapshotParams</var>, and <var>initiatorOrigin</var>.<dt>a supported image, video, or audio type<dd>Return the result of <a href=document-lifecycle.html#navigate-media id=populating-a-session-history-entry:navigate-media>loading a media document</a> given
     <var>navigationParams</var> and <var>type</var>.<dt>"<code>application/pdf</code>"<dt>"<code>text/pdf</code>"<dd>If the user agent's <a id=populating-a-session-history-entry:pdf-viewer-supported href=system-state.html#pdf-viewer-supported>PDF viewer supported</a> is true, return the result of <a href=document-lifecycle.html#read-ua-inline id=populating-a-session-history-entry:read-ua-inline-3>creating a document for inline content that doesn't have a
     DOM</a> given <var>navigationParams</var>'s <a href=#navigation-params-navigable id=populating-a-session-history-entry:navigation-params-navigable-3>navigable</a>, <var>navigationParams</var>'s <a href=#navigation-params-id id=populating-a-session-history-entry:navigation-params-id-3>id</a>, <var>navigationParams</var>'s <a href=#navigation-params-nav-timing-type id=populating-a-session-history-entry:navigation-params-nav-timing-type-3>navigation timing type</a>, and
     <var>navigationParams</var>'s <a href=#navigation-params-user-involvement id=populating-a-session-history-entry:navigation-params-user-involvement-3>user
     involvement</a>.</dl>

    <p>Otherwise, proceed onward.</p>

    <p>An <dfn id=explicitly-supported-xml-mime-type>explicitly supported XML MIME type</dfn> is an <a id=populating-a-session-history-entry:xml-mime-type-2 href=https://mimesniff.spec.whatwg.org/#xml-mime-type data-x-internal=xml-mime-type>XML MIME type</a> for which
    the user agent is configured to use an external application to render the content, or for which
    the user agent has dedicated processing rules. For example, a web browser with a built-in Atom
    feed viewer would be said to explicitly support the <code id=populating-a-session-history-entry:application/atom+xml><a href=indices.html#application/atom+xml>application/atom+xml</a></code> MIME
    type.</p>

    <p>An <dfn id=explicitly-supported-json-mime-type>explicitly supported JSON MIME type</dfn> is a <a id=populating-a-session-history-entry:json-mime-type-2 href=https://mimesniff.spec.whatwg.org/#json-mime-type data-x-internal=json-mime-type>JSON MIME type</a> for which
    the user agent is configured to use an external application to render the content, or for which
    the user agent has dedicated processing rules.</p>

    <p class=note>In both cases, the external application or user agent will either <a href=document-lifecycle.html#read-ua-inline id=populating-a-session-history-entry:read-ua-inline-4>display the content inline</a> directly in
    <var>navigationParams</var>'s <a href=#navigation-params-navigable id=populating-a-session-history-entry:navigation-params-navigable-4>navigable</a>, or
    <a href=#hand-off-to-external-software id=populating-a-session-history-entry:hand-off-to-external-software-3>hand it off to external software</a>. Both
    happen in the steps below.</p>
   <li id=navigate-non-Document><p>If, given <var>type</var>, the new resource is to be handled
   by displaying some sort of inline content, e.g., a native rendering of the content or an error
   message because the specified type is not supported, then return the result of <a href=document-lifecycle.html#read-ua-inline id=populating-a-session-history-entry:read-ua-inline-5>creating a document for inline content that doesn't have a
   DOM</a> given <var>navigationParams</var>'s <a href=#navigation-params-navigable id=populating-a-session-history-entry:navigation-params-navigable-5>navigable</a>, <var>navigationParams</var>'s <a href=#navigation-params-id id=populating-a-session-history-entry:navigation-params-id-4>id</a>, <var>navigationParams</var>'s <a href=#navigation-params-nav-timing-type id=populating-a-session-history-entry:navigation-params-nav-timing-type-4>navigation timing type</a>, and
   <var>navigationParams</var>'s <a href=#navigation-params-user-involvement id=populating-a-session-history-entry:navigation-params-user-involvement-4>user
   involvement</a>.<li><p>Otherwise, the document's <var>type</var> is such that the resource will not affect
   <var>navigationParams</var>'s <a href=#navigation-params-navigable id=populating-a-session-history-entry:navigation-params-navigable-6>navigable</a>, e.g.,
   because the resource is to be handed to an external application or because it is an unknown type
   that will be processed by <a id=populating-a-session-history-entry:handle-as-a-download-2 href=links.html#handle-as-a-download>handle as a download</a>. <a href=#hand-off-to-external-software id=populating-a-session-history-entry:hand-off-to-external-software-4>Hand-off to external
   software</a> given <var>navigationParams</var>'s <a href=#navigation-params-response id=populating-a-session-history-entry:navigation-params-response-13>response</a>, <var>navigationParams</var>'s <a href=#navigation-params-navigable id=populating-a-session-history-entry:navigation-params-navigable-7>navigable</a>, <var>navigationParams</var>'s <a href=#navigation-params-sandboxing id=populating-a-session-history-entry:navigation-params-sandboxing-4>final sandboxing flag set</a>,
   <var>sourceSnapshotParams</var>'s <a href=#source-snapshot-params-activation id=populating-a-session-history-entry:source-snapshot-params-activation-4>has transient
   activation</a>, and <var>initiatorOrigin</var>.<li><p>Return null.</ol>


  <h4 id=applying-the-history-step><span class=secno>7.4.6</span> Applying the history step<a href=#applying-the-history-step class=self-link></a></h4>

  <p>For both navigation and traversal, once we have an idea of where we want to head to in the
  session history, much of the work comes about in applying that notion to the <a id=applying-the-history-step:traversable-navigable href=document-sequences.html#traversable-navigable>traversable
  navigable</a> and the relevant <code id=applying-the-history-step:document><a href=dom.html#document>Document</a></code>. For navigations, this work generally
  occurs toward the end of the process; for traversals, it is the beginning.</p>

  <h5 id=updating-the-traversable><span class=secno>7.4.6.1</span> Updating the traversable<a href=#updating-the-traversable class=self-link></a></h5>

  <p>Ensuring a <a href=document-sequences.html#traversable-navigable id=updating-the-traversable:traversable-navigable>traversable</a> ends up at the right
  session history step is particularly complex, as it can involve coordinating across multiple
  <a id=updating-the-traversable:navigable href=document-sequences.html#navigable>navigable</a> descendants of the traversable, <a href=#populating-a-session-history-entry>populating</a> them in parallel, and then
  synchronizing back up to ensure everyone has the same view of the result. This is further
  complicated by the existence of synchronous same-document navigations being mixed together with
  cross-document navigations, and how web pages have come to have certain relative timing
  expectations.</p>

  <p>A <dfn id=changing-navigable-continuation-state>changing navigable continuation state</dfn> is used to store information during the
  <a href=#apply-the-history-step id=updating-the-traversable:apply-the-history-step>apply the history step</a> algorithm, allowing parts of the algorithm to continue only
  after other parts have finished. It is a <a id=updating-the-traversable:struct href=https://infra.spec.whatwg.org/#struct data-x-internal=struct>struct</a> with:</p>

  <dl><dt><dfn id=changing-nav-continuation-displayed-document>displayed document</dfn><dd>A <code id=updating-the-traversable:document><a href=dom.html#document>Document</a></code><dt><dfn id=changing-nav-continuation-target-entry>target entry</dfn><dd>A <a href=#session-history-entry id=updating-the-traversable:session-history-entry>session history entry</a><dt><dfn id=changing-nav-continuation-navigable>navigable</dfn><dd>A <a id=updating-the-traversable:navigable-2 href=document-sequences.html#navigable>navigable</a><dt><dfn id=changing-nav-continuation-update-only>update only</dfn><dd>A boolean</dl>

  <hr>

  <p>Although all updates to the <a id=updating-the-traversable:traversable-navigable-2 href=document-sequences.html#traversable-navigable>traversable navigable</a> end up in the same <a href=#apply-the-history-step id=updating-the-traversable:apply-the-history-step-2>apply
  the history step</a> algorithm, each possible entry point comes along with some minor
  customizations:</p>

  <p>To <dfn id=update-for-navigable-creation/destruction>update for navigable creation/destruction</dfn> given a <a id=updating-the-traversable:traversable-navigable-3 href=document-sequences.html#traversable-navigable>traversable
  navigable</a> <var>traversable</var>:</p>

  <ol><li><p>Let <var>step</var> be <var>traversable</var>'s <a href=document-sequences.html#tn-current-session-history-step id=updating-the-traversable:tn-current-session-history-step>current session history step</a>.<li><p>Return the result of <a href=#apply-the-history-step id=updating-the-traversable:apply-the-history-step-3>applying the history
   step</a> <var>step</var> to <var>traversable</var> given false, null, null, "<code id=updating-the-traversable:uni-none><a href=#uni-none>none</a></code>", and null.</ol>

  <p>To <dfn id=apply-the-push/replace-history-step>apply the push/replace history step</dfn> given a non-negative integer <var>step</var>
  to a <a id=updating-the-traversable:traversable-navigable-4 href=document-sequences.html#traversable-navigable>traversable navigable</a> <var>traversable</var>, given a <a href=#history-handling-behavior id=updating-the-traversable:history-handling-behavior>history handling
  behavior</a> <var>historyHandling</var> and a <a href=#user-navigation-involvement id=updating-the-traversable:user-navigation-involvement>user navigation involvement</a>
  <var>userInvolvement</var>:</p>

  <ol><li><p>Return the result of <a href=#apply-the-history-step id=updating-the-traversable:apply-the-history-step-4>applying the history
   step</a> <var>step</var> to <var>traversable</var> given false, null, null,
   <var>userInvolvement</var>, and <var>historyHandling</var>.</ol>

  <p class=note><a href=#apply-the-push/replace-history-step id=updating-the-traversable:apply-the-push/replace-history-step>Apply the push/replace history step</a> never passes <a href=#source-snapshot-params id=updating-the-traversable:source-snapshot-params>source
  snapshot params</a> or an initiator <a id=updating-the-traversable:navigable-3 href=document-sequences.html#navigable>navigable</a> to <a href=#apply-the-history-step id=updating-the-traversable:apply-the-history-step-5>apply the history
  step</a>. This is because those checks are done earlier in the <a href=#navigate id=updating-the-traversable:navigate>navigation</a> algorithm.</p>

  <p>To <dfn id=apply-the-reload-history-step>apply the reload history step</dfn> to a <a id=updating-the-traversable:traversable-navigable-5 href=document-sequences.html#traversable-navigable>traversable navigable</a>
  <var>traversable</var> given <a href=#user-navigation-involvement id=updating-the-traversable:user-navigation-involvement-2>user navigation involvement</a>
  <var>userInvolvement</var>:</p>

  <ol><li><p>Let <var>step</var> be <var>traversable</var>'s <a href=document-sequences.html#tn-current-session-history-step id=updating-the-traversable:tn-current-session-history-step-2>current session history step</a>.<li><p>Return the result of <a href=#apply-the-history-step id=updating-the-traversable:apply-the-history-step-6>applying the history
   step</a> <var>step</var> to <var>traversable</var> given true, null, null,
   <var>userInvolvement</var>, and "<code id=updating-the-traversable:dom-navigationtype-reload><a href=nav-history-apis.html#dom-navigationtype-reload>reload</a></code>".</ol>

  <p class=note><a href=#apply-the-reload-history-step id=updating-the-traversable:apply-the-reload-history-step>Apply the reload history step</a> never passes <a href=#source-snapshot-params id=updating-the-traversable:source-snapshot-params-2>source snapshot
  params</a> or an initiator <a id=updating-the-traversable:navigable-4 href=document-sequences.html#navigable>navigable</a> to <a href=#apply-the-history-step id=updating-the-traversable:apply-the-history-step-7>apply the history step</a>. This
  is because reloading is always treated as if it were done by the <a id=updating-the-traversable:navigable-5 href=document-sequences.html#navigable>navigable</a> itself,
  even in cases like <code>parent.location.reload()</code>.</p>

  <p>To <dfn id=apply-the-traverse-history-step>apply the traverse history step</dfn> given a non-negative integer <var>step</var> to a
  <a id=updating-the-traversable:traversable-navigable-6 href=document-sequences.html#traversable-navigable>traversable navigable</a> <var>traversable</var>, with <a href=#source-snapshot-params id=updating-the-traversable:source-snapshot-params-3>source snapshot
  params</a> <var>sourceSnapshotParams</var>, <a id=updating-the-traversable:navigable-6 href=document-sequences.html#navigable>navigable</a> <var>initiatorToCheck</var>,
  and <a href=#user-navigation-involvement id=updating-the-traversable:user-navigation-involvement-3>user navigation involvement</a> <var>userInvolvement</var>:</p>

  <ol><li><p>Return the result of <a href=#apply-the-history-step id=updating-the-traversable:apply-the-history-step-8>applying the history
   step</a> <var>step</var> to <var>traversable</var> given true,
   <var>sourceSnapshotParams</var>, <var>initiatorToCheck</var>,
   <var>userInvolvement</var>, and "<code id=updating-the-traversable:dom-navigationtype-traverse><a href=nav-history-apis.html#dom-navigationtype-traverse>traverse</a></code>".</ol>

  <p>To <dfn id=resume-applying-the-traverse-history-step>resume applying the traverse history step</dfn> given a non-negative integer
  <var>step</var>, a <a id=updating-the-traversable:traversable-navigable-7 href=document-sequences.html#traversable-navigable>traversable navigable</a> <var>traversable</var>, and <a href=#user-navigation-involvement id=updating-the-traversable:user-navigation-involvement-4>user
  navigation involvement</a> <var>userInvolvement</var>, <a href=#apply-the-history-step id=updating-the-traversable:apply-the-history-step-9>apply</a> <var>step</var> to <var>traversable</var> given false, null, null,
  <var>userInvolvement</var>, and "<code id=updating-the-traversable:dom-navigationtype-traverse-2><a href=nav-history-apis.html#dom-navigationtype-traverse>traverse</a></code>".</p>

  <p class=note>When resuming a traverse, we are already past the cancelation, initiator, and
  source snapshot checks, and this traversal has already been determined to be a same-document
  traversal. Hence, we can pass false and null for those arguments.</p>

  <hr>

  <p>Now for the algorithm itself.</p>

  <p id=update-the-session-history-with-the-new-page>To <dfn id=apply-the-history-step>apply the history step</dfn> given a
  non-negative integer <var>step</var> to a <a id=updating-the-traversable:traversable-navigable-8 href=document-sequences.html#traversable-navigable>traversable navigable</a>
  <var>traversable</var>, with boolean <var>checkForCancelation</var>, <a href=#source-snapshot-params id=updating-the-traversable:source-snapshot-params-4>source snapshot
  params</a>-or-null <var>sourceSnapshotParams</var>, <a id=updating-the-traversable:navigable-7 href=document-sequences.html#navigable>navigable</a>-or-null
  <var>initiatorToCheck</var>, <a href=#user-navigation-involvement id=updating-the-traversable:user-navigation-involvement-5>user navigation involvement</a> <var>userInvolvement</var>,
  and <code id=updating-the-traversable:navigationtype><a href=nav-history-apis.html#navigationtype>NavigationType</a></code>-or-null <var>navigationType</var>, perform the following steps.
  They return "<code>initiator-disallowed</code>", "<code>canceled-by-beforeunload</code>", "<code>canceled-by-navigate</code>", or
  "<code>applied</code>".</p>

  <ol><li><p><a id=updating-the-traversable:assert href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: This is running within <var>traversable</var>'s <a href=document-sequences.html#tn-session-history-traversal-queue id=updating-the-traversable:tn-session-history-traversal-queue>session history traversal queue</a>.<li><p>Let <var>targetStep</var> be the result of <a href=#getting-the-used-step id=updating-the-traversable:getting-the-used-step>getting the used step</a> given
   <var>traversable</var> and <var>step</var>.<li>
    <p>If <var>initiatorToCheck</var> is not null, then:</p>

    <ol><li><p><a id=updating-the-traversable:assert-2 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>sourceSnapshotParams</var> is not null.<li><p><a href=https://infra.spec.whatwg.org/#list-iterate id=updating-the-traversable:list-iterate data-x-internal=list-iterate>For each</a> <var>navigable</var> of <a href=#get-all-navigables-whose-current-session-history-entry-will-change-or-reload id=updating-the-traversable:get-all-navigables-whose-current-session-history-entry-will-change-or-reload>get all
     navigables whose current session history entry will change or reload</a>: if
     <var>initiatorToCheck</var> is not <a href=#allowed-to-navigate id=updating-the-traversable:allowed-to-navigate>allowed by sandboxing to navigate</a>
     <var>navigable</var> given <var>sourceSnapshotParams</var>, then return "<code>initiator-disallowed</code>".</ol>
   <li><p>Let <var>navigablesCrossingDocuments</var> be the result of <a href=#getting-all-navigables-that-might-experience-a-cross-document-traversal id=updating-the-traversable:getting-all-navigables-that-might-experience-a-cross-document-traversal>getting all navigables
   that might experience a cross-document traversal</a> given <var>traversable</var> and
   <var>targetStep</var>.<li><p>If <var>checkForCancelation</var> is true, and the result of <a href=#checking-if-unloading-is-canceled id=updating-the-traversable:checking-if-unloading-is-canceled>checking if unloading
   is canceled</a> given <var>navigablesCrossingDocuments</var>, <var>traversable</var>,
   <var>targetStep</var>, and <var>userInvolvement</var> is not "<code>continue</code>",
   then return that result.<li><p>Let <var>changingNavigables</var> be the result of <a href=#get-all-navigables-whose-current-session-history-entry-will-change-or-reload id=updating-the-traversable:get-all-navigables-whose-current-session-history-entry-will-change-or-reload-2>get all navigables whose current
   session history entry will change or reload</a> given <var>traversable</var> and
   <var>targetStep</var>.<li><p>Let <var>nonchangingNavigablesThatStillNeedUpdates</var> be the result of <a href=#getting-all-navigables-that-only-need-history-object-length/index-update id=updating-the-traversable:getting-all-navigables-that-only-need-history-object-length/index-update>getting
   all navigables that only need history object length/index update</a> given
   <var>traversable</var> and <var>targetStep</var>.<li>
    <p><a href=https://infra.spec.whatwg.org/#list-iterate id=updating-the-traversable:list-iterate-2 data-x-internal=list-iterate>For each</a> <var>navigable</var> of
    <var>changingNavigables</var>:</p>

    <ol><li><p>Let <var>targetEntry</var> be the result of <a href=#getting-the-target-history-entry id=updating-the-traversable:getting-the-target-history-entry>getting the target history
     entry</a> given <var>navigable</var> and <var>targetStep</var>.<li><p>Set <var>navigable</var>'s <a href=document-sequences.html#nav-current-history-entry id=updating-the-traversable:nav-current-history-entry>current session
     history entry</a> to <var>targetEntry</var>.<li><p><a href=#set-the-ongoing-navigation id=updating-the-traversable:set-the-ongoing-navigation>Set the ongoing navigation</a> for <var>navigable</var> to "<code>traversal</code>".</ol>
   <li><p>Let <var>totalChangeJobs</var> be the <a href=https://infra.spec.whatwg.org/#list-size id=updating-the-traversable:list-size data-x-internal=list-size>size</a> of
   <var>changingNavigables</var>.<li><p>Let <var>completedChangeJobs</var> be 0.<li>
    <p>Let <var>changingNavigableContinuations</var> be an empty <a id=updating-the-traversable:queue href=https://infra.spec.whatwg.org/#queue data-x-internal=queue>queue</a> of <a href=#changing-navigable-continuation-state id=updating-the-traversable:changing-navigable-continuation-state>changing navigable continuation
    states</a>.</p>

    <p class=note>This queue is used to split the operations on <var>changingNavigables</var>
    into two parts. Specifically, <var>changingNavigableContinuations</var> holds data for the <a href=#continuations-dequeue>second part</a>.</p>
   <li>
    <p><a href=https://infra.spec.whatwg.org/#list-iterate id=updating-the-traversable:list-iterate-3 data-x-internal=list-iterate>For each</a> <var>navigable</var> of
    <var>changingNavigables</var>, <a id=updating-the-traversable:queue-a-global-task href=webappapis.html#queue-a-global-task>queue a global task</a> on the <a id=updating-the-traversable:navigation-and-traversal-task-source href=webappapis.html#navigation-and-traversal-task-source>navigation and
    traversal task source</a> of <var>navigable</var>'s <a href=document-sequences.html#nav-window id=updating-the-traversable:nav-window>active
    window</a> to run the steps:</p>

    <p class=note>This set of steps are split into two parts to allow synchronous navigations to
    be processed before documents unload. State is stored in
    <var>changingNavigableContinuations</var> for the <a href=#continuations-dequeue>second
    part</a>.</p>

    <ol><li><p>Let <var>displayedEntry</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=updating-the-traversable:nav-active-history-entry>active session history entry</a>.<li><p>Let <var>targetEntry</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-current-history-entry id=updating-the-traversable:nav-current-history-entry-2>current session history entry</a>.<li>
      <p>Let <var>changingNavigableContinuation</var> be a <a href=#changing-navigable-continuation-state id=updating-the-traversable:changing-navigable-continuation-state-2>changing navigable continuation
      state</a> with:</p>

      <dl class=props><dt><a href=#changing-nav-continuation-displayed-document id=updating-the-traversable:changing-nav-continuation-displayed-document>displayed document</a><dd><var>displayedEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document>document</a><dt><a href=#changing-nav-continuation-target-entry id=updating-the-traversable:changing-nav-continuation-target-entry>target entry</a><dd><var>targetEntry</var><dt><a href=#changing-nav-continuation-navigable id=updating-the-traversable:changing-nav-continuation-navigable>navigable</a><dd><var>navigable</var><dt><a href=#changing-nav-continuation-update-only id=updating-the-traversable:changing-nav-continuation-update-only>update-only</a><dd>false</dl>
     <li>
      <p>If <var>displayedEntry</var> is <var>targetEntry</var> and <var>targetEntry</var>'s <a href=#she-document-state id=updating-the-traversable:she-document-state>document state</a>'s <a href=#document-state-reload-pending id=updating-the-traversable:document-state-reload-pending>reload pending</a> is false, then:</p>

      <ol><li><p>Set <var>changingNavigableContinuation</var>'s <a href=#changing-nav-continuation-update-only id=updating-the-traversable:changing-nav-continuation-update-only-2>update-only</a> to true.<li><p><a id=updating-the-traversable:enqueue href=https://infra.spec.whatwg.org/#queue-enqueue data-x-internal=enqueue>Enqueue</a> <var>changingNavigableContinuation</var> on
       <var>changingNavigableContinuations</var>.<li><p>Abort these steps.</ol>

      <p class=note>This case occurs due to a <a href=#finalize-a-same-document-navigation id=updating-the-traversable:finalize-a-same-document-navigation>synchronous navigation</a> which already updated the <a href=document-sequences.html#nav-active-history-entry id=updating-the-traversable:nav-active-history-entry-2>active session history entry</a>.</p>
     <li>
      <p>Switch on <var>navigationType</var>:</p>

      <dl class=switch><dt>"<code id=updating-the-traversable:dom-navigationtype-reload-2><a href=nav-history-apis.html#dom-navigationtype-reload>reload</a></code>"<dd><p><a id=updating-the-traversable:assert-3 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>targetEntry</var>'s <a href=#she-document-state id=updating-the-traversable:she-document-state-2>document state</a>'s <a href=#document-state-reload-pending id=updating-the-traversable:document-state-reload-pending-2>reload pending</a> is true.<dt>"<code id=updating-the-traversable:dom-navigationtype-traverse-3><a href=nav-history-apis.html#dom-navigationtype-traverse>traverse</a></code>"<dd><p><a id=updating-the-traversable:assert-4 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>targetEntry</var>'s
       <a href=#she-document-state id=updating-the-traversable:she-document-state-3>document state</a>'s <a href=#document-state-ever-populated id=updating-the-traversable:document-state-ever-populated>ever populated</a> is true.<dt>"<code id=updating-the-traversable:dom-navigationtype-replace><a href=nav-history-apis.html#dom-navigationtype-replace>replace</a></code>"<dd><p><a id=updating-the-traversable:assert-5 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>targetEntry</var>'s <a href=#she-step id=updating-the-traversable:she-step>step</a>
       is <var>displayedEntry</var>'s <a href=#she-step id=updating-the-traversable:she-step-2>step</a> and
       <var>targetEntry</var>'s <a href=#she-document-state id=updating-the-traversable:she-document-state-4>document state</a>'s <a href=#document-state-ever-populated id=updating-the-traversable:document-state-ever-populated-2>ever populated</a> is false.<dt>"<code id=updating-the-traversable:dom-navigationtype-push><a href=nav-history-apis.html#dom-navigationtype-push>push</a></code>"<dd><p><a id=updating-the-traversable:assert-6 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>targetEntry</var>'s <a href=#she-step id=updating-the-traversable:she-step-3>step</a> is
       <var>displayedEntry</var>'s <a href=#she-step id=updating-the-traversable:she-step-4>step</a> + 1 and
       <var>targetEntry</var>'s <a href=#she-document-state id=updating-the-traversable:she-document-state-5>document state</a>'s <a href=#document-state-ever-populated id=updating-the-traversable:document-state-ever-populated-3>ever populated</a> is false.</dl>
     <li><p>Let <var>oldOrigin</var> be <var>targetEntry</var>'s <a href=#she-document-state id=updating-the-traversable:she-document-state-6>document state</a>'s <a href=#document-state-origin id=updating-the-traversable:document-state-origin>origin</a>.<li id=descendant-navigable-traversal-navigate-events>
      <p>If all of the following are true:</p>

      <ul><li><p><var>navigable</var> is not <var>traversable</var>;<li><p><var>targetEntry</var> is not <var>navigable</var>'s <a href=document-sequences.html#nav-current-history-entry id=updating-the-traversable:nav-current-history-entry-3>current session history entry</a>; and<li><p><var>oldOrigin</var> is the <a href=browsers.html#same-origin id=updating-the-traversable:same-origin>same</a> as
       <var>navigable</var>'s <a href=document-sequences.html#nav-current-history-entry id=updating-the-traversable:nav-current-history-entry-4>current session history entry</a>'s <a href=#she-document-state id=updating-the-traversable:she-document-state-7>document state</a>'s <a href=#document-state-origin id=updating-the-traversable:document-state-origin-2>origin</a>,</ul>

      <p>then:</p>

      <ol><li><p>Let <var>navigation</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-window id=updating-the-traversable:nav-window-2>active window</a>'s <a href=nav-history-apis.html#window-navigation-api id=updating-the-traversable:window-navigation-api>navigation API</a>.<li><p><a id=updating-the-traversable:fire-a-traverse-navigate-event href=nav-history-apis.html#fire-a-traverse-navigate-event>Fire a traverse <code>navigate</code> event</a> at
       <var>navigation</var> given <var>targetEntry</var> and <var>userInvolvement</var>.</ol>
     <li>
      <p>If <var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-2>document</a> is null, or
      <var>targetEntry</var>'s <a href=#she-document-state id=updating-the-traversable:she-document-state-8>document state</a>'s <a href=#document-state-reload-pending id=updating-the-traversable:document-state-reload-pending-3>reload pending</a> is true, then:</p>

      <ol><li><p>Let <var>navTimingType</var> be "<code id=updating-the-traversable:dom-navigationtimingtype-back_forward><a data-x-internal=dom-navigationtimingtype-back_forward href=https://w3c.github.io/navigation-timing/#dom-navigationtimingtype-back_forward>back_forward</a></code>" if
       <var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-3>document</a> is null; otherwise
       "<code id=updating-the-traversable:dom-navigationtimingtype-back_forward-2><a data-x-internal=dom-navigationtimingtype-back_forward href=https://w3c.github.io/navigation-timing/#dom-navigationtimingtype-back_forward>reload</a></code>".<li><p>Let <var>targetSnapshotParams</var> be the result of <a href=#snapshotting-target-snapshot-params id=updating-the-traversable:snapshotting-target-snapshot-params>snapshotting target
       snapshot params</a> given <var>navigable</var>.<li><p>Let <var>potentiallyTargetSpecificSourceSnapshotParams</var> be
       <var>sourceSnapshotParams</var>.<li>
        <p>If <var>potentiallyTargetSpecificSourceSnapshotParams</var> is null, then set it to the
        result of <a href=#snapshotting-source-snapshot-params id=updating-the-traversable:snapshotting-source-snapshot-params>snapshotting source snapshot params</a> given <var>navigable</var>'s
        <a href=document-sequences.html#nav-document id=updating-the-traversable:nav-document>active document</a>.</p>

        <p class=note>In this case there is no clear source of the traversal/reload. We treat this
        situation as if <var>navigable</var> navigated itself, but note that some properties of
        <var>targetEntry</var>'s original initiator are preserved in <var>targetEntry</var>'s <a href=#she-document-state id=updating-the-traversable:she-document-state-9>document state</a>, such as the <a href=#document-state-initiator-origin id=updating-the-traversable:document-state-initiator-origin>initiator origin</a> and <a href=#document-state-request-referrer id=updating-the-traversable:document-state-request-referrer>referrer</a>, which will appropriately influence
        the navigation.</p>
       <li><p>Set <var>targetEntry</var>'s <a href=#she-document-state id=updating-the-traversable:she-document-state-10>document
       state</a>'s <a href=#document-state-reload-pending id=updating-the-traversable:document-state-reload-pending-4>reload pending</a> to
       false.<li><p>Let <var>allowPOST</var> be <var>targetEntry</var>'s <a href=#she-document-state id=updating-the-traversable:she-document-state-11>document state</a>'s <a href=#document-state-reload-pending id=updating-the-traversable:document-state-reload-pending-5>reload pending</a>.</p>

       <li><p><a id=updating-the-traversable:in-parallel href=infrastructure.html#in-parallel>In parallel</a>, <a href="#attempt-to-populate-the-history-entry's-document" id="updating-the-traversable:attempt-to-populate-the-history-entry's-document">attempt to populate the history entry's
       document</a> for <var>targetEntry</var>, given <var>navigable</var>,
       <var>potentiallyTargetSpecificSourceSnapshotParams</var>, <var>targetSnapshotParams</var>,
       <var>userInvolvement</var>, with <i id=updating-the-traversable:attempt-to-populate-allow-post><a href=#attempt-to-populate-allow-post>allowPOST</a></i> set
       to <var>allowPOST</var> and <a href=#attempt-to-populate-completion-steps id=updating-the-traversable:attempt-to-populate-completion-steps><i>completionSteps</i></a> set to
       <a id=updating-the-traversable:queue-a-global-task-2 href=webappapis.html#queue-a-global-task>queue a global task</a> on the <a id=updating-the-traversable:navigation-and-traversal-task-source-2 href=webappapis.html#navigation-and-traversal-task-source>navigation and traversal task source</a>
       given <var>navigable</var>'s <a href=document-sequences.html#nav-window id=updating-the-traversable:nav-window-3>active window</a> to run
       <var>afterDocumentPopulated</var>.</ol>

      <p>Otherwise, run <var>afterDocumentPopulated</var> <a id=updating-the-traversable:immediately href=infrastructure.html#immediately>immediately</a>.</p>

      <p>In both cases, let <var>afterDocumentPopulated</var> be the following steps:</p>

      <ol><li>
        <p>If <var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-4>document</a> is null, then
        set <var>changingNavigableContinuation</var>'s <a href=#changing-nav-continuation-update-only id=updating-the-traversable:changing-nav-continuation-update-only-3>update-only</a> to true.</p>

        <p class=note>This means we tried to populate the document, but were unable to do so,
        e.g. because of the server returning a 204.</p>

        <div class=note>
         <p>These kinds of failed navigations or traversals will not be signaled to the <a href=nav-history-apis.html#navigation-api>navigation API</a> (e.g., through the promises of any
         <a id=updating-the-traversable:navigation-api-method-tracker href=nav-history-apis.html#navigation-api-method-tracker>navigation API method tracker</a>, or the <code id=updating-the-traversable:event-navigateerror><a href=indices.html#event-navigateerror>navigateerror</a></code> event). Doing so would leak information
         about the timing of responses from other origins, in the cross-origin case, and providing
         different results in the cross-origin vs. same-origin cases was deemed too confusing.</p>

         <p>However, implementations could use this opportunity to clear any promise handlers for
         the <code id=updating-the-traversable:dom-navigationtransition-finished><a href=nav-history-apis.html#dom-navigationtransition-finished>navigation.transition.finished</a></code>
         promise, as they are guaranteed at this point to never run. And, they might wish to
         <a id=updating-the-traversable:report-a-warning-to-the-console href=https://console.spec.whatwg.org/#report-a-warning-to-the-console data-x-internal=report-a-warning-to-the-console>report a warning to the console</a> if any part of the navigation API initiated
         these navigations, to make it clear to the web developer why their promises will never
         settle and events will never fire.</p>
        </div>
       <li>
        <p>If <var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-5>document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=updating-the-traversable:concept-document-origin data-x-internal=concept-document-origin>origin</a> is not <var>oldOrigin</var>, then set
        <var>targetEntry</var>'s <a href=#she-classic-history-api-state id=updating-the-traversable:she-classic-history-api-state>classic history API
        state</a> to <a id=updating-the-traversable:structuredserializeforstorage href=structured-data.html#structuredserializeforstorage>StructuredSerializeForStorage</a>(null).</p>

        <p class=note>This clears history state when the origin changed vs a previous load of
        <var>targetEntry</var> without a redirect occuring. This can happen due to a change in CSP
        sandbox headers.</p>
       <li>
        <p>If all of the following are true:</p>

        <ul><li><p><var>navigable</var>'s <a href=document-sequences.html#nav-parent id=updating-the-traversable:nav-parent>parent</a> is null;<li><p><var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-6>document</a>'s <a href=document-sequences.html#concept-document-bc id=updating-the-traversable:concept-document-bc>browsing context</a> is not an <a id=updating-the-traversable:auxiliary-browsing-context href=document-sequences.html#auxiliary-browsing-context>auxiliary browsing
         context</a> whose <a id=updating-the-traversable:opener-browsing-context href=document-sequences.html#opener-browsing-context>opener browsing context</a> is non-null; and<li><p><var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-7>document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=updating-the-traversable:concept-document-origin-2 data-x-internal=concept-document-origin>origin</a> is not <var>oldOrigin</var>,</ul>

        <p>then set <var>targetEntry</var>'s <a href=#she-document-state id=updating-the-traversable:she-document-state-12>document
        state</a>'s <a href=#document-state-nav-target-name id=updating-the-traversable:document-state-nav-target-name>navigable target name</a>
        to the empty string.</p>
       <li>
        <p><a id=updating-the-traversable:enqueue-2 href=https://infra.spec.whatwg.org/#queue-enqueue data-x-internal=enqueue>Enqueue</a> <var>changingNavigableContinuation</var> on
        <var>changingNavigableContinuations</var>.</p>

        <p class=note>The rest of this job <a href=#continuations-dequeue>runs later</a> in
        this algorithm.</p>
       </ol>
     </ol>
   <li><p>Let <var>navigablesThatMustWaitBeforeHandlingSyncNavigation</var> be an empty
   <a id=updating-the-traversable:set href=https://infra.spec.whatwg.org/#ordered-set data-x-internal=set>set</a>.<li>
    <p>While <var>completedChangeJobs</var> does not equal <var>totalChangeJobs</var>:</p>

    <ol><li>
      <p>If <var>traversable</var>'s <a href=document-sequences.html#tn-running-nested-apply-history-step id=updating-the-traversable:tn-running-nested-apply-history-step>running
      nested apply history step</a> is false, then:</p>

      <ol><li id=sync-navigations-jump-queue>
        <p>While <var>traversable</var>'s <a href=document-sequences.html#tn-session-history-traversal-queue id=updating-the-traversable:tn-session-history-traversal-queue-2>session
        history traversal queue</a>'s <a href=#session-history-traversal-parallel-queue-algorithm-set id=updating-the-traversable:session-history-traversal-parallel-queue-algorithm-set>algorithm set</a> <a href=https://infra.spec.whatwg.org/#list-contain id=updating-the-traversable:list-contains data-x-internal=list-contains>contains</a> one or more <a href=#session-history-traversal-parallel-queue-sync-nav-steps id=updating-the-traversable:session-history-traversal-parallel-queue-sync-nav-steps>synchronous navigation
        steps</a> with a <a href=#session-history-traversal-parallel-queue-sync-nav-steps-target-nav id=updating-the-traversable:session-history-traversal-parallel-queue-sync-nav-steps-target-nav>target
        navigable</a> not <a href=https://infra.spec.whatwg.org/#list-contain id=updating-the-traversable:list-contains-2 data-x-internal=list-contains>contained</a> in
        <var>navigablesThatMustWaitBeforeHandlingSyncNavigation</var>:</p>

        <ol><li><p>Let <var>steps</var> be the first <a href=https://infra.spec.whatwg.org/#list-item id=updating-the-traversable:list-item data-x-internal=list-item>item</a> in
         <var>traversable</var>'s <a href=document-sequences.html#tn-session-history-traversal-queue id=updating-the-traversable:tn-session-history-traversal-queue-3>session history
         traversal queue</a>'s <a href=#session-history-traversal-parallel-queue-algorithm-set id=updating-the-traversable:session-history-traversal-parallel-queue-algorithm-set-2>algorithm set</a> that
         is <a href=#session-history-traversal-parallel-queue-sync-nav-steps id=updating-the-traversable:session-history-traversal-parallel-queue-sync-nav-steps-2>synchronous
         navigation steps</a> with a <a href=#session-history-traversal-parallel-queue-sync-nav-steps-target-nav id=updating-the-traversable:session-history-traversal-parallel-queue-sync-nav-steps-target-nav-2>target
         navigable</a> not <a href=https://infra.spec.whatwg.org/#list-contain id=updating-the-traversable:list-contains-3 data-x-internal=list-contains>contained</a> in
         <var>navigablesThatMustWaitBeforeHandlingSyncNavigation</var>.<li><p><a href=https://infra.spec.whatwg.org/#list-remove id=updating-the-traversable:list-remove data-x-internal=list-remove>Remove</a> <var>steps</var> from
         <var>traversable</var>'s <a href=document-sequences.html#tn-session-history-traversal-queue id=updating-the-traversable:tn-session-history-traversal-queue-4>session history
         traversal queue</a>'s <a href=#session-history-traversal-parallel-queue-algorithm-set id=updating-the-traversable:session-history-traversal-parallel-queue-algorithm-set-3>algorithm
         set</a>.<li><p>Set <var>traversable</var>'s <a href=document-sequences.html#tn-running-nested-apply-history-step id=updating-the-traversable:tn-running-nested-apply-history-step-2>running nested apply history step</a> to
         true.<li><p>Run <var>steps</var>.<li><p>Set <var>traversable</var>'s <a href=document-sequences.html#tn-running-nested-apply-history-step id=updating-the-traversable:tn-running-nested-apply-history-step-3>running nested apply history step</a> to
         false.</ol>

        <p class=note>Synchronous navigations that are intended to take place before this
        traversal jump the queue at this point, so they can be added to the correct place in
        <var>traversable</var>'s <a href=document-sequences.html#tn-session-history-entries id=updating-the-traversable:tn-session-history-entries>session history
        entries</a> before this traversal potentially unloads their document. <a href=#sync-navigation-steps-queue-jumping-examples>More details can be found
        here</a>.</p>
       </ol>
     <li id=continuations-dequeue><p>Let <var>changingNavigableContinuation</var> be the result
     of <a href=https://infra.spec.whatwg.org/#queue-dequeue id=updating-the-traversable:dequeue data-x-internal=dequeue>dequeuing</a> from
     <var>changingNavigableContinuations</var>.<li><p>If <var>changingNavigableContinuation</var> is nothing, then
     <a id=updating-the-traversable:continue href=https://infra.spec.whatwg.org/#iteration-continue data-x-internal=continue>continue</a>.<li><p>Let <var>displayedDocument</var> be <var>changingNavigableContinuation</var>'s <a href=#changing-nav-continuation-displayed-document id=updating-the-traversable:changing-nav-continuation-displayed-document-2>displayed document</a>.<li><p>Let <var>targetEntry</var> be <var>changingNavigableContinuation</var>'s <a href=#changing-nav-continuation-target-entry id=updating-the-traversable:changing-nav-continuation-target-entry-2>target entry</a>.<li><p>Let <var>navigable</var> be <var>changingNavigableContinuation</var>'s <a href=#changing-nav-continuation-navigable id=updating-the-traversable:changing-nav-continuation-navigable-2>navigable</a>.<li>
      <p>Let (<var>scriptHistoryLength</var>, <var>scriptHistoryIndex</var>) be the result of
      <a href=#getting-the-history-object-length-and-index id=updating-the-traversable:getting-the-history-object-length-and-index>getting the history object length and index</a> given <var>traversable</var> and
      <var>targetStep</var>.</p>

      <p class=note>These values might have changed since they were last calculated.</p>
     <li>
      <p><a href=https://infra.spec.whatwg.org/#list-append id=updating-the-traversable:list-append data-x-internal=list-append>Append</a> <var>navigable</var> to
      <var>navigablesThatMustWaitBeforeHandlingSyncNavigation</var>.</p>

      <p class=note>Once a navigable has reached this point in traversal, additionally queued
      synchronous navigation steps are likely to be intended to occur after this traversal rather
      than before it, so they no longer jump the queue. <a href=#sync-navigation-steps-queue-jumping-examples>More details can be found here</a>.</p>
     <li><p>Let <var>entriesForNavigationAPI</var> be the result of <a href=#getting-session-history-entries-for-the-navigation-api id=updating-the-traversable:getting-session-history-entries-for-the-navigation-api>getting session history
     entries for the navigation API</a> given <var>navigable</var> and
     <var>targetStep</var>.<li>
      <p>If <var>changingNavigableContinuation</var>'s <a href=#changing-nav-continuation-update-only id=updating-the-traversable:changing-nav-continuation-update-only-4>update-only</a> is true, or
      <var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-8>document</a> is
      <var>displayedDocument</var>, then:</p>

      <p class=note>This is a same-document navigation: we proceed without unloading.</p>

      <ol><li>
        <p><a href=#set-the-ongoing-navigation id=updating-the-traversable:set-the-ongoing-navigation-2>Set the ongoing navigation</a> for <var>navigable</var> to null.</p>

        <p class=note>This allows new <a href=#navigate id=updating-the-traversable:navigate-2>navigations</a> of
        <var>navigable</var> to start, whereas during the traversal they were blocked.</p>
       <li><p><a id=updating-the-traversable:queue-a-global-task-3 href=webappapis.html#queue-a-global-task>Queue a global task</a> on the <a id=updating-the-traversable:navigation-and-traversal-task-source-3 href=webappapis.html#navigation-and-traversal-task-source>navigation and traversal task
       source</a> given <var>navigable</var>'s <a href=document-sequences.html#nav-window id=updating-the-traversable:nav-window-4>active window</a> to
       perform <var>afterPotentialUnloads</var>.</ol>
     <li>
      <p>Otherwise:</p>

      <ol><li><p><a id=updating-the-traversable:assert-7 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>navigationType</var> is not null.<li><p><a href=#deactivate-a-document-for-a-cross-document-navigation id=updating-the-traversable:deactivate-a-document-for-a-cross-document-navigation>Deactivate</a>
       <var>displayedDocument</var>, given <var>userInvolvement</var>, <var>targetEntry</var>,
       <var>navigationType</var>, and <var>afterPotentialUnloads</var>.</ol>
     <li>
      <p>In both cases, let <var>afterPotentialUnloads</var> be the following steps:</p>

      <ol><li><p>Let <var>previousEntry</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=updating-the-traversable:nav-active-history-entry-3>active session history entry</a>.<li><p>If <var>changingNavigableContinuation</var>'s <a href=#changing-nav-continuation-update-only id=updating-the-traversable:changing-nav-continuation-update-only-5>update-only</a> is false, then
       <a href=#activate-history-entry id=updating-the-traversable:activate-history-entry>activate history entry</a> <var>targetEntry</var> for
       <var>navigable</var>.<li><p>Let <var>updateDocument</var> be an algorithm step which performs <a href=#update-document-for-history-step-application id=updating-the-traversable:update-document-for-history-step-application>update
       document for history step application</a> given <var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-9>document</a>, <var>targetEntry</var>,
       <var>changingNavigableContinuation</var>'s <a href=#changing-nav-continuation-update-only id=updating-the-traversable:changing-nav-continuation-update-only-6>update-only</a>,
       <var>scriptHistoryLength</var>, <var>scriptHistoryIndex</var>, <var>navigationType</var>,
       <var>entriesForNavigationAPI</var>, and <var>previousEntry</var>.<li><p>If <var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-10>document</a> is equal to
       <var>displayedDocument</var>, then perform <var>updateDocument</var>.<li><p>Otherwise, <a id=updating-the-traversable:queue-a-global-task-4 href=webappapis.html#queue-a-global-task>queue a global task</a> on the <a id=updating-the-traversable:navigation-and-traversal-task-source-4 href=webappapis.html#navigation-and-traversal-task-source>navigation and traversal task
       source</a> given <var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-11>document</a>'s
       <a id=updating-the-traversable:concept-relevant-global href=webappapis.html#concept-relevant-global>relevant global object</a> to perform <var>updateDocument</var>.<li><p>Increment <var>completedChangeJobs</var>.</ol>
     </ol>
   <li>
    <p>Let <var>totalNonchangingJobs</var> be the <a href=https://infra.spec.whatwg.org/#list-size id=updating-the-traversable:list-size-2 data-x-internal=list-size>size</a> of
    <var>nonchangingNavigablesThatStillNeedUpdates</var>.</p>

    <p class=note>This step onwards deliberately waits for all the previous operations to
    complete, as they include <a href=#sync-navigations-jump-queue>processing synchronous
    navigations</a> which will also post tasks to update history length and index.</p>
   <li><p>Let <var>completedNonchangingJobs</var> be 0.<li><p>Let (<var>scriptHistoryLength</var>, <var>scriptHistoryIndex</var>) be the result of
   <a href=#getting-the-history-object-length-and-index id=updating-the-traversable:getting-the-history-object-length-and-index-2>getting the history object length and index</a> given <var>traversable</var> and
   <var>targetStep</var>.<li>
    <p><a href=https://infra.spec.whatwg.org/#list-iterate id=updating-the-traversable:list-iterate-4 data-x-internal=list-iterate>For each</a> <var>navigable</var> of
    <var>nonchangingNavigablesThatStillNeedUpdates</var>, <a id=updating-the-traversable:queue-a-global-task-5 href=webappapis.html#queue-a-global-task>queue a global task</a> on the
    <a id=updating-the-traversable:navigation-and-traversal-task-source-5 href=webappapis.html#navigation-and-traversal-task-source>navigation and traversal task source</a> given <var>navigable</var>'s <a href=document-sequences.html#nav-window id=updating-the-traversable:nav-window-5>active window</a> to run the steps:</p>

    <ol><li><p>Let <var>document</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-document id=updating-the-traversable:nav-document-2>active
     document</a>.<li><p>Set <var>document</var>'s <a href=nav-history-apis.html#doc-history id=updating-the-traversable:doc-history>history object</a>'s <a href=nav-history-apis.html#concept-history-index id=updating-the-traversable:concept-history-index>index</a> to <var>scriptHistoryIndex</var>.<li><p>Set <var>document</var>'s <a href=nav-history-apis.html#doc-history id=updating-the-traversable:doc-history-2>history object</a>'s <a href=nav-history-apis.html#concept-history-length id=updating-the-traversable:concept-history-length>length</a> to <var>scriptHistoryLength</var>.<li><p>Increment <var>completedNonchangingJobs</var>.</ol>
   <li><p>Wait for <var>completedNonchangingJobs</var> to equal
   <var>totalNonchangingJobs</var>.<li><p>Set <var>traversable</var>'s <a href=document-sequences.html#tn-current-session-history-step id=updating-the-traversable:tn-current-session-history-step-3>current
   session history step</a> to <var>targetStep</var>.<li><p>Return "<code>applied</code>".</ol>

  <p>To <dfn id=deactivate-a-document-for-a-cross-document-navigation>deactivate a document for a cross-document navigation</dfn> given a
  <code id=updating-the-traversable:document-2><a href=dom.html#document>Document</a></code> <var>displayedDocument</var>, a <a href=#user-navigation-involvement id=updating-the-traversable:user-navigation-involvement-6>user navigation involvement</a>
  <var>userNavigationInvolvement</var>, a <a href=#session-history-entry id=updating-the-traversable:session-history-entry-2>session history entry</a> <var>targetEntry</var>,
  a <code id=updating-the-traversable:navigationtype-2><a href=nav-history-apis.html#navigationtype>NavigationType</a></code> <var>navigationType</var>, and <var>afterPotentialUnloads</var>,
  which is an algorithm that receives no arguments:</p>

  <ol><li><p>Let <var>navigable</var> be <var>displayedDocument</var>'s
   <a id=updating-the-traversable:node-navigable href=document-sequences.html#node-navigable>node navigable</a>.<li><p>Let <var>potentiallyTriggerViewTransition</var> be false.<li><p>Let <var>isBrowserUINavigation</var> be true if
   <var>userNavigationInvolvement</var> is "<code id=updating-the-traversable:uni-browser-ui><a href=#uni-browser-ui>browser UI</a></code>"; otherwise false.<li><p>Set <var>potentiallyTriggerViewTransition</var> to the result of calling
   <a id=updating-the-traversable:can-navigation-trigger-a-cross-document-view-transition href=https://drafts.csswg.org/css-view-transitions-2/#can-navigation-trigger-a-cross-document-view-transition data-x-internal=can-navigation-trigger-a-cross-document-view-transition>can navigation trigger a cross-document view-transition?</a> given
   <var>displayedDocument</var>, <var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-12>document</a>, <var>navigationType</var>, and
   <var>isBrowserUINavigation</var>.<li>
    <p>If <var>potentiallyTriggerViewTransition</var> is false, then:</p>

    <ol><li>
      <p>Let <var>firePageSwapBeforeUnload</var> be the following step:</p>

      <ol><li><p><a href=#fire-the-pageswap-event id=updating-the-traversable:fire-the-pageswap-event>Fire the <code>pageswap</code> event</a> given
       <var>displayedDocument</var>, <var>targetEntry</var>, <var>navigationType</var>, and
       null.</ol>
     <li>
      <p><a href=#set-the-ongoing-navigation id=updating-the-traversable:set-the-ongoing-navigation-3>Set the ongoing navigation</a> for <var>navigable</var> to null.</p>

      <p class=note>This allows new <a href=#navigate id=updating-the-traversable:navigate-3>navigations</a> of
      <var>navigable</var> to start, whereas during the traversal they were blocked.</p>
     <li><p><a id=updating-the-traversable:unload-a-document-and-its-descendants href=document-lifecycle.html#unload-a-document-and-its-descendants>Unload a document and its descendants</a> given
     <var>displayedDocument</var>, <var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-13>document</a>, <var>afterPotentialUnloads</var>, and
     <var>firePageSwapBeforeUnload</var>.</ol>
   <li>
    <p>Otherwise, <a id=updating-the-traversable:queue-a-global-task-6 href=webappapis.html#queue-a-global-task>queue a global task</a> on the
    <a id=updating-the-traversable:navigation-and-traversal-task-source-6 href=webappapis.html#navigation-and-traversal-task-source>navigation and traversal task source</a> given <var>navigable</var>'s <a href=document-sequences.html#nav-window id=updating-the-traversable:nav-window-6>active window</a> to run the steps:</p>

    <ol><li>
      <p>Let <var>proceedWithNavigationAfterViewTransitionCapture</var> be the following
      step:</p>

      <ol><li>
        <p><a href=#tn-append-session-history-traversal-steps id=updating-the-traversable:tn-append-session-history-traversal-steps>Append the following session
        history traversal steps</a> to <var>navigable</var>'s <a href=document-sequences.html#nav-traversable id=updating-the-traversable:nav-traversable>traversable navigable</a>:</p>

        <ol><li>
          <p><a href=#set-the-ongoing-navigation id=updating-the-traversable:set-the-ongoing-navigation-4>Set the ongoing navigation</a> for <var>navigable</var> to null.</p>

          <p class=note>This allows new <a href=#navigate id=updating-the-traversable:navigate-4>navigations</a> of
          <var>navigable</var> to start, whereas during the traversal they were blocked.</p>
         <li><p><a id=updating-the-traversable:unload-a-document-and-its-descendants-2 href=document-lifecycle.html#unload-a-document-and-its-descendants>Unload a document and its descendants</a> given
         <var>displayedDocument</var>, <var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-14>document</a>, and <var>afterPotentialUnloads</var>.</ol>
       </ol>
     <li><p>Let <var>viewTransition</var> be the result of
     <a id=updating-the-traversable:setting-up-a-cross-document-view-transition href=https://drafts.csswg.org/css-view-transitions-2/#setup-cross-document-view-transition data-x-internal=setting-up-a-cross-document-view-transition>setting up a cross-document view-transition</a> given
     <var>displayedDocument</var>, <var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-15>document</a>, <var>navigationType</var>, and
     <var>proceedWithNavigationAfterViewTransitionCapture</var>.<li><p><a href=#fire-the-pageswap-event id=updating-the-traversable:fire-the-pageswap-event-2>Fire the <code>pageswap</code> event</a> given
     <var>displayedDocument</var>, <var>targetEntry</var>, <var>navigationType</var>, and
     <var>viewTransition</var>.</p>

     <li>
      <p>If <var>viewTransition</var> is null, then run
      <var>proceedWithNavigationAfterViewTransitionCapture</var>.</p>

      <p class=note>In the case where a view transition started, the view transitions
      algorithms are responsible for calling
      <var>proceedWithNavigationAfterViewTransitionCapture</var>.</p>
     </ol>
   </ol>

  <p>To <dfn id=fire-the-pageswap-event>fire the <code>pageswap</code> event</dfn> given a
  <code id=updating-the-traversable:document-3><a href=dom.html#document>Document</a></code> <var>displayedDocument</var>, a <a href=#session-history-entry id=updating-the-traversable:session-history-entry-3>session history entry</a>
  <var>targetEntry</var>, a <code id=updating-the-traversable:navigationtype-3><a href=nav-history-apis.html#navigationtype>NavigationType</a></code> <var>navigationType</var>, and a
  <code id=updating-the-traversable:viewtransition><a data-x-internal=viewtransition href=https://drafts.csswg.org/css-view-transitions/#viewtransition>ViewTransition</a></code>-or-null <var>viewTransition</var>:</p>

  <ol><li><p><a id=updating-the-traversable:assert-8 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: this is running as part of a <a href=webappapis.html#concept-task id=updating-the-traversable:concept-task>task</a> queued on <var>displayedDocument</var>'s
   <a id=updating-the-traversable:relevant-agent href=webappapis.html#relevant-agent>relevant agent</a>'s <a href=webappapis.html#concept-agent-event-loop id=updating-the-traversable:concept-agent-event-loop>event loop</a>.<li><p>Let <var>navigation</var> be <var>displayedDocument</var>'s
   <a id=updating-the-traversable:concept-relevant-global-2 href=webappapis.html#concept-relevant-global>relevant global object</a>'s <a href=nav-history-apis.html#window-navigation-api id=updating-the-traversable:window-navigation-api-2>navigation API</a>.<li><p>Let <var>activation</var> be null.<li>
    <p>If all of the following are true:</p>

    <ul><li><p><var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-16>document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=updating-the-traversable:concept-document-origin-3 data-x-internal=concept-document-origin>origin</a> is <a id=updating-the-traversable:same-origin-2 href=browsers.html#same-origin>same origin</a> with
     <var>displayedDocument</var>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=updating-the-traversable:concept-document-origin-4 data-x-internal=concept-document-origin>origin</a>;
     and<li><p><var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-17>document</a>'s
     <a id=updating-the-traversable:was-created-via-cross-origin-redirects href=dom.html#was-created-via-cross-origin-redirects>was created via cross-origin redirects</a> is false, or <var>targetEntry</var>'s
     <a href=#she-document id=updating-the-traversable:she-document-18>document</a>'s <a href=#latest-entry id=updating-the-traversable:latest-entry>latest entry</a> is not null,</ul>

    <p>then:</p>

    <ol><li>
      <p>Let <var>destinationEntry</var> be determined by switching on
      <var>navigationType</var>:</p>

      <dl class=switch><dt>"<code id=updating-the-traversable:dom-navigationtype-reload-3><a href=nav-history-apis.html#dom-navigationtype-reload>reload</a></code>"<dd><p>The <a href=nav-history-apis.html#navigation-current-entry id=updating-the-traversable:navigation-current-entry>current entry</a> of
       <var>navigation</var><dt>"<code id=updating-the-traversable:dom-navigationtype-traverse-4><a href=nav-history-apis.html#dom-navigationtype-traverse>traverse</a></code>"<dd><p>The <code id=updating-the-traversable:navigationhistoryentry><a href=nav-history-apis.html#navigationhistoryentry>NavigationHistoryEntry</a></code> in <var>navigation</var>'s <a href=nav-history-apis.html#navigation-entry-list id=updating-the-traversable:navigation-entry-list>entry list</a> whose <a href=nav-history-apis.html#nhe-she id=updating-the-traversable:nhe-she>session history entry</a> is <var>targetEntry</var><dt>"<code id=updating-the-traversable:dom-navigationtype-push-2><a href=nav-history-apis.html#dom-navigationtype-push>push</a></code>"<dt>"<code id=updating-the-traversable:dom-navigationtype-replace-2><a href=nav-history-apis.html#dom-navigationtype-replace>replace</a></code>"<dd><p>A new <code id=updating-the-traversable:navigationhistoryentry-2><a href=nav-history-apis.html#navigationhistoryentry>NavigationHistoryEntry</a></code> in <var>displayedDocument</var>'s <a href=webappapis.html#concept-relevant-realm id=updating-the-traversable:concept-relevant-realm>relevant realm</a> with its <a href=nav-history-apis.html#nhe-she id=updating-the-traversable:nhe-she-2>session history entry</a> set to <var>targetEntry</var></dl>
     <li>
      <p>Set <var>activation</var> to a <a id=updating-the-traversable:new href=https://webidl.spec.whatwg.org/#new data-x-internal=new>new</a> <code id=updating-the-traversable:navigationactivation><a href=nav-history-apis.html#navigationactivation>NavigationActivation</a></code>
      created in <var>displayedDocument</var>'s <a href=webappapis.html#concept-relevant-realm id=updating-the-traversable:concept-relevant-realm-2>relevant
      realm</a>, with</p>

      <dl class=props><dt><a href=nav-history-apis.html#nav-activation-old-entry id=updating-the-traversable:nav-activation-old-entry>old entry</a><dd>the <a href=nav-history-apis.html#navigation-current-entry id=updating-the-traversable:navigation-current-entry-2>current entry</a> of
       <var>navigation</var><dt><a href=nav-history-apis.html#nav-activation-new-entry id=updating-the-traversable:nav-activation-new-entry>new entry</a><dd><var>destinationEntry</var><dt><a href=nav-history-apis.html#nav-activation-navigation-type id=updating-the-traversable:nav-activation-navigation-type>navigation type</a><dd><var>navigationType</var></dl>
     </ol>

    <p class=note>This means that a cross-origin redirect during a navigation would result in a
    null <code id=updating-the-traversable:dom-pageswapevent-activation><a href=nav-history-apis.html#dom-pageswapevent-activation>activation</a></code> in the old document's
    <code id=updating-the-traversable:pageswapevent><a href=nav-history-apis.html#pageswapevent>PageSwapEvent</a></code>, unless the new document is being restored from <a href=#note-bfcache>bfcache</a>.</p>
   <li><p><a href=https://dom.spec.whatwg.org/#concept-event-fire id=updating-the-traversable:concept-event-fire data-x-internal=concept-event-fire>Fire an event</a> named
   <code id=updating-the-traversable:event-pageswap><a href=indices.html#event-pageswap>pageswap</a></code> at <var>displayedDocument</var>'s
   <a id=updating-the-traversable:concept-relevant-global-3 href=webappapis.html#concept-relevant-global>relevant global object</a>, using <code id=updating-the-traversable:pageswapevent-2><a href=nav-history-apis.html#pageswapevent>PageSwapEvent</a></code> with its <code id=updating-the-traversable:dom-pageswapevent-activation-2><a href=nav-history-apis.html#dom-pageswapevent-activation>activation</a></code> set to <var>activation</var>,
   and its <code id=updating-the-traversable:dom-pageswapevent-viewtransition><a href=nav-history-apis.html#dom-pageswapevent-viewtransition>viewTransition</a></code> set to
   <var>viewTransition</var>.</ol>

  <p>To <dfn id=activate-history-entry>activate history entry</dfn> <a href=#session-history-entry id=updating-the-traversable:session-history-entry-4>session history entry</a> <var>entry</var> for
  <a id=updating-the-traversable:navigable-8 href=document-sequences.html#navigable>navigable</a> <var>navigable</var>:</p>

  <ol><li><p><a href=#save-persisted-state id=updating-the-traversable:save-persisted-state>Save persisted state</a> to the <a id=updating-the-traversable:navigable-9 href=document-sequences.html#navigable>navigable</a>'s <a href=document-sequences.html#nav-active-history-entry id=updating-the-traversable:nav-active-history-entry-4>active session history entry</a>.<li><p>Let <var>newDocument</var> be <var>entry</var>'s <a href=#she-document id=updating-the-traversable:she-document-19>document</a>.<li><p><a id=updating-the-traversable:assert-9 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>newDocument</var>'s <a id=updating-the-traversable:is-initial-about:blank href=dom.html#is-initial-about:blank>is initial
   <code>about:blank</code></a> is false, i.e., we never traverse back to the <a href=dom.html#is-initial-about:blank id=updating-the-traversable:is-initial-about:blank-2>initial <code>about:blank</code></a> <code id=updating-the-traversable:document-4><a href=dom.html#document>Document</a></code> because it
   always gets <a href=#navigate-convert-to-replace>replaced</a> when we navigate away from
   it.<li><p>Set <var>navigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=updating-the-traversable:nav-active-history-entry-5>active session history
   entry</a> to <var>entry</var>.<li><p><a href=#make-active id=updating-the-traversable:make-active>Make active</a> <var>newDocument</var>.</ol>

  <p>To <dfn id=getting-the-used-step>get the used step</dfn> given a <a id=updating-the-traversable:traversable-navigable-9 href=document-sequences.html#traversable-navigable>traversable
  navigable</a> <var>traversable</var>, and a non-negative integer <var>step</var>, perform the
  following steps. They return a non-negative integer.</p>

  <ol><li><p>Let <var>steps</var> be the result of <a href=#getting-all-used-history-steps id=updating-the-traversable:getting-all-used-history-steps>getting all used history steps</a> within
   <var>traversable</var>.<li>
    <p>Return the greatest <a href=https://infra.spec.whatwg.org/#list-item id=updating-the-traversable:list-item-2 data-x-internal=list-item>item</a> in <var>steps</var> that is less
    than or equal to <var>step</var>.</p>

    <p class=note>This caters for situations where there's no <a href=#session-history-entry id=updating-the-traversable:session-history-entry-5>session history entry</a>
    with <a href=#she-step id=updating-the-traversable:she-step-5>step</a> <var>step</var>, due to the removal of a
    <a id=updating-the-traversable:navigable-10 href=document-sequences.html#navigable>navigable</a>.</p>
   </ol>

  <p>To <dfn id=getting-the-history-object-length-and-index>get the history object length and
  index</dfn> given a <a id=updating-the-traversable:traversable-navigable-10 href=document-sequences.html#traversable-navigable>traversable navigable</a> <var>traversable</var>, and a non-negative
  integer <var>step</var>, perform the following steps. They return a <a id=updating-the-traversable:tuple href=https://infra.spec.whatwg.org/#tuple data-x-internal=tuple>tuple</a> of two
  non-negative integers.</p>

  <ol><li><p>Let <var>steps</var> be the result of <a href=#getting-all-used-history-steps id=updating-the-traversable:getting-all-used-history-steps-2>getting all used history steps</a> within
   <var>traversable</var>.<li><p>Let <var>scriptHistoryLength</var> be the <a href=https://infra.spec.whatwg.org/#list-size id=updating-the-traversable:list-size-3 data-x-internal=list-size>size</a> of
   <var>steps</var>.<li>
    <p><a id=updating-the-traversable:assert-10 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>steps</var> <a href=https://infra.spec.whatwg.org/#list-contain id=updating-the-traversable:list-contains-4 data-x-internal=list-contains>contains</a>
    <var>step</var>.</p>

    <p class=note>It is assumed that <var>step</var> has been adjusted by <a href=#getting-the-used-step id=updating-the-traversable:getting-the-used-step-2>getting the used
    step</a>.</p>
   <li><p>Let <var>scriptHistoryIndex</var> be the index of <var>step</var> in
   <var>steps</var>.<li><p>Return (<var>scriptHistoryLength</var>, <var>scriptHistoryIndex</var>).</ol>

  <p>To <dfn id=get-all-navigables-whose-current-session-history-entry-will-change-or-reload>get all navigables whose current session history entry will change or reload</dfn>
  given a <a id=updating-the-traversable:traversable-navigable-11 href=document-sequences.html#traversable-navigable>traversable navigable</a> <var>traversable</var>, and a non-negative integer
  <var>targetStep</var>, perform the following steps. They return a <a id=updating-the-traversable:list href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a> of <a href=document-sequences.html#navigable id=updating-the-traversable:navigable-11>navigables</a>.</p>

  <ol><li><p>Let <var>results</var> be an empty <a id=updating-the-traversable:list-2 href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a>.<li>
    <p>Let <var>navigablesToCheck</var> be « <var>traversable</var> ».</p>

    <p class=note>This list is extended in the loop below.</p>
   <li>
    <p><a href=https://infra.spec.whatwg.org/#list-iterate id=updating-the-traversable:list-iterate-5 data-x-internal=list-iterate>For each</a> <var>navigable</var> of
    <var>navigablesToCheck</var>:</p>

    <ol><li><p>Let <var>targetEntry</var> be the result of <a href=#getting-the-target-history-entry id=updating-the-traversable:getting-the-target-history-entry-2>getting the target history
     entry</a> given <var>navigable</var> and <var>targetStep</var>.<li><p>If <var>targetEntry</var> is not <var>navigable</var>'s <a href=document-sequences.html#nav-current-history-entry id=updating-the-traversable:nav-current-history-entry-5>current session history entry</a> or
     <var>targetEntry</var>'s <a href=#she-document-state id=updating-the-traversable:she-document-state-13>document state</a>'s <a href=#document-state-reload-pending id=updating-the-traversable:document-state-reload-pending-6>reload pending</a> is true, then <a href=https://infra.spec.whatwg.org/#list-append id=updating-the-traversable:list-append-2 data-x-internal=list-append>append</a> <var>navigable</var> to <var>results</var>.<li>
      <p>If <var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-20>document</a> is
      <var>navigable</var>'s <a href=document-sequences.html#nav-document id=updating-the-traversable:nav-document-3>document</a>, and
      <var>targetEntry</var>'s <a href=#she-document-state id=updating-the-traversable:she-document-state-14>document state</a>'s <a href=#document-state-reload-pending id=updating-the-traversable:document-state-reload-pending-7>reload pending</a> is false, then <a href=https://infra.spec.whatwg.org/#list-extend id=updating-the-traversable:list-extend data-x-internal=list-extend>extend</a> <var>navigablesToCheck</var> with the <a href=document-sequences.html#child-navigable id=updating-the-traversable:child-navigable>child navigables</a> of <var>navigable</var>.</p>

      <p class=note>Adding <a href=document-sequences.html#child-navigable id=updating-the-traversable:child-navigable-2>child navigables</a> to
      <var>navigablesToCheck</var> means those navigables will also be checked by this loop. <a href=document-sequences.html#child-navigable id=updating-the-traversable:child-navigable-3>Child navigables</a> are only checked if the
      <var>navigable</var>'s <a href=document-sequences.html#nav-document id=updating-the-traversable:nav-document-4>active document</a> will not change as
      part of this traversal.</p>
     </ol>
   <li><p>Return <var>results</var>.</ol>

  <p>To <dfn id=getting-all-navigables-that-only-need-history-object-length/index-update>get
  all navigables that only need history object length/index update</dfn> given a <a id=updating-the-traversable:traversable-navigable-12 href=document-sequences.html#traversable-navigable>traversable
  navigable</a> <var>traversable</var>, and a non-negative integer <var>targetStep</var>,
  perform the following steps. They return a <a id=updating-the-traversable:list-3 href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a> of <a href=document-sequences.html#navigable id=updating-the-traversable:navigable-12>navigables</a>.</p>

  <p class=note>Other <a href=document-sequences.html#navigable id=updating-the-traversable:navigable-13>navigables</a> might not be impacted by the
  traversal. For example, if the response is a 204, the currently active document will remain.
  Additionally, going 'back' after a 204 will change the <a href=document-sequences.html#nav-current-history-entry id=updating-the-traversable:nav-current-history-entry-6>current session history entry</a>, but the <a href=document-sequences.html#nav-active-history-entry id=updating-the-traversable:nav-active-history-entry-6>active session history entry</a> will already be
  correct.</p>

  <ol><li><p>Let <var>results</var> be an empty <a id=updating-the-traversable:list-4 href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a>.<li>
    <p>Let <var>navigablesToCheck</var> be « <var>traversable</var> ».</p>

    <p class=note>This list is extended in the loop below.</p>
   <li>
    <p><a href=https://infra.spec.whatwg.org/#list-iterate id=updating-the-traversable:list-iterate-6 data-x-internal=list-iterate>For each</a> <var>navigable</var> of
    <var>navigablesToCheck</var>:</p>

    <ol><li><p>Let <var>targetEntry</var> be the result of <a href=#getting-the-target-history-entry id=updating-the-traversable:getting-the-target-history-entry-3>getting the target history
     entry</a> given <var>navigable</var> and <var>targetStep</var>.<li>
      <p>If <var>targetEntry</var> is <var>navigable</var>'s <a href=document-sequences.html#nav-current-history-entry id=updating-the-traversable:nav-current-history-entry-7>current session history entry</a> and
      <var>targetEntry</var>'s <a href=#she-document-state id=updating-the-traversable:she-document-state-15>document state</a>'s <a href=#document-state-reload-pending id=updating-the-traversable:document-state-reload-pending-8>reload pending</a> is false, then:</p>

      <ol><li><p><a href=https://infra.spec.whatwg.org/#list-append id=updating-the-traversable:list-append-3 data-x-internal=list-append>Append</a> <var>navigable</var> to
       <var>results</var>.<li>
        <p><a href=https://infra.spec.whatwg.org/#list-extend id=updating-the-traversable:list-extend-2 data-x-internal=list-extend>Extend</a> <var>navigablesToCheck</var> with
        <var>navigable</var>'s <a href=document-sequences.html#child-navigable id=updating-the-traversable:child-navigable-4>child navigables</a>.</p>

        <p class=note>Adding <a href=document-sequences.html#child-navigable id=updating-the-traversable:child-navigable-5>child navigables</a> to
        <var>navigablesToCheck</var> means those navigables will also be checked by this loop.
        <a href=document-sequences.html#child-navigable id=updating-the-traversable:child-navigable-6>child navigables</a> are only checked if the
        <var>navigable</var>'s <a href=document-sequences.html#nav-document id=updating-the-traversable:nav-document-5>active document</a> will not change
        as part of this traversal.</p>
       </ol>
     </ol>
   <li><p>Return <var>results</var>.</ol>

  <p>To <dfn id=getting-the-target-history-entry>get the target history entry</dfn> given a
  <a id=updating-the-traversable:navigable-14 href=document-sequences.html#navigable>navigable</a> <var>navigable</var>, and a non-negative integer <var>step</var>, perform
  the following steps. They return a <a href=#session-history-entry id=updating-the-traversable:session-history-entry-6>session history entry</a>.</p>

  <ol><li><p>Let <var>entries</var> be the result of <a href=#getting-session-history-entries id=updating-the-traversable:getting-session-history-entries>getting session history entries</a> for
   <var>navigable</var>.<li><p>Return the <a href=https://infra.spec.whatwg.org/#list-item id=updating-the-traversable:list-item-3 data-x-internal=list-item>item</a> in <var>entries</var> that has the
   greatest <a href=#she-step id=updating-the-traversable:she-step-6>step</a> less than or equal to <var>step</var>.</ol>

  <div id=example-getting-the-target-history-entry class=example><a href=#example-getting-the-target-history-entry class=self-link></a>
   <p>To see why <a href=#getting-the-target-history-entry id=updating-the-traversable:getting-the-target-history-entry-4>getting the target history entry</a> returns the entry with the greatest
   <a href=#she-step id=updating-the-traversable:she-step-7>step</a> less than or equal to the input step, consider the following
   <a id=updating-the-traversable:jake-diagram href=document-sequences.html#jake-diagram>Jake diagram</a>:</p>

   
   <table class=jake-diagram><thead><tr><td><th class=step>0<th class=step>1<th class=step>2<th class=step>3<tbody><tr><th><code>top</code><td colspan=3 class=doc-0>/t<td colspan=1 class=doc-0>/t#foo<tr><th><code>frames[0]</code><td colspan=1 class=doc-1>/i-0-a<td colspan=3 class=doc-2>/i-0-b</table>

   <p>For the input step 1, the target history entry for the <code>top</code> navigable
   is the <code>/t</code> entry, whose <a href=#she-step id=updating-the-traversable:she-step-8>step</a> is 0, while the target history entry for the <code>frames[0]</code> navigable is the <code>/i-0-b</code> entry, whose <a href=#she-step id=updating-the-traversable:she-step-9>step</a> is 1:</p>

   
   <table class=jake-diagram><thead><tr><td><th class=step>0<th class="step current">1<th class=step>2<th class=step>3<tbody><tr><th><code>top</code><td colspan=3 class="doc-0 current next-is-same-doc">/t<td colspan=1 class="doc-0 prev-is-same-doc">/t#foo<tr><th><code>frames[0]</code><td colspan=1 class=doc-1>/i-0-a<td colspan=3 class="doc-2 current">/i-0-b</table>

   <p>Similarly, given the input step 3 we get the <code>top</code> entry whose <a href=#she-step id=updating-the-traversable:she-step-10>step</a> is 3, and the <code>frames[0]</code> entry whose <a href=#she-step id=updating-the-traversable:she-step-11>step</a> is 1:</p>

   
   <table class=jake-diagram><thead><tr><td><th class=step>0<th class=step>1<th class=step>2<th class="step current">3<tbody><tr><th><code>top</code><td colspan=3 class="doc-0 next-is-same-doc">/t<td colspan=1 class="doc-0 current prev-is-same-doc">/t#foo<tr><th><code>frames[0]</code><td colspan=1 class=doc-1>/i-0-a<td colspan=3 class="doc-2 current">/i-0-b</table>
  </div>

  <p>To <dfn id=getting-all-navigables-that-might-experience-a-cross-document-traversal>get
  all navigables that might experience a cross-document traversal</dfn> given a <a id=updating-the-traversable:traversable-navigable-13 href=document-sequences.html#traversable-navigable>traversable
  navigable</a> <var>traversable</var>, and a non-negative integer <var>targetStep</var>,
  perform the following steps. They return a <a id=updating-the-traversable:list-5 href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a> of <a href=document-sequences.html#navigable id=updating-the-traversable:navigable-15>navigables</a>.</p>

  <div class=note>
   <p>From <var>traversable</var>'s <a href=document-sequences.html#tn-session-history-traversal-queue id=updating-the-traversable:tn-session-history-traversal-queue-5>session
   history traversal queue</a>'s perspective, these documents are candidates for going
   cross-document during the traversal described by <var>targetStep</var>. They will not experience
   a cross-document traversal if the status code for their target document is HTTP 204 No Content.</p>

   <p>Note that if a given <a id=updating-the-traversable:navigable-16 href=document-sequences.html#navigable>navigable</a> might experience a cross-document traversal, this
   algorithm will return <a id=updating-the-traversable:navigable-17 href=document-sequences.html#navigable>navigable</a> but not its <a href=document-sequences.html#child-navigable id=updating-the-traversable:child-navigable-7>child
   navigables</a>. Those would end up <a href=document-lifecycle.html#unload-a-document id=updating-the-traversable:unload-a-document>unloaded</a>, not
   traversed.</p>
  </div>

  <ol><li><p>Let <var>results</var> be an empty <a id=updating-the-traversable:list-6 href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a>.<li>
    <p>Let <var>navigablesToCheck</var> be « <var>traversable</var> ».</p>

    <p class=note>This list is extended in the loop below.</p>
   <li>
    <p><a href=https://infra.spec.whatwg.org/#list-iterate id=updating-the-traversable:list-iterate-7 data-x-internal=list-iterate>For each</a> <var>navigable</var> of
    <var>navigablesToCheck</var>:</p>

    <ol><li><p>Let <var>targetEntry</var> be the result of <a href=#getting-the-target-history-entry id=updating-the-traversable:getting-the-target-history-entry-5>getting the target history
     entry</a> given <var>navigable</var> and <var>targetStep</var>.<li>
      <p>If <var>targetEntry</var>'s <a href=#she-document id=updating-the-traversable:she-document-21>document</a> is not
      <var>navigable</var>'s <a href=document-sequences.html#nav-document id=updating-the-traversable:nav-document-6>document</a> or
      <var>targetEntry</var>'s <a href=#she-document-state id=updating-the-traversable:she-document-state-16>document state</a>'s <a href=#document-state-reload-pending id=updating-the-traversable:document-state-reload-pending-9>reload pending</a> is true, then <a href=https://infra.spec.whatwg.org/#list-append id=updating-the-traversable:list-append-4 data-x-internal=list-append>append</a> <var>navigable</var> to <var>results</var>.</p>

      <p class=note>Although <var>navigable</var>'s <a href=document-sequences.html#nav-active-history-entry id=updating-the-traversable:nav-active-history-entry-7>active history entry</a> can change synchronously, the
      new entry will always have the same <code id=updating-the-traversable:document-5><a href=dom.html#document>Document</a></code>, so accessing
      <var>navigable</var>'s <a href=document-sequences.html#nav-document id=updating-the-traversable:nav-document-7>document</a> is reliable.</p>
     <li>
      <p>Otherwise, <a href=https://infra.spec.whatwg.org/#list-extend id=updating-the-traversable:list-extend-3 data-x-internal=list-extend>extend</a> <var>navigablesToCheck</var> with
      <var>navigable</var>'s <a href=document-sequences.html#child-navigable id=updating-the-traversable:child-navigable-8>child navigables</a>.</p>

      <p class=note>Adding <a href=document-sequences.html#child-navigable id=updating-the-traversable:child-navigable-9>child navigables</a> to
      <var>navigablesToCheck</var> means those navigables will also be checked by this loop. <a href=document-sequences.html#child-navigable id=updating-the-traversable:child-navigable-10>Child navigables</a> are only checked if the
      <var>navigable</var>'s <a href=document-sequences.html#nav-document id=updating-the-traversable:nav-document-8>active document</a> will not change as
      part of this traversal.</p>
     </ol>
   <li><p>Return <var>results</var>.</ol>


  <h5 id=updating-the-document><span class=secno>7.4.6.2</span> Updating the document<a href=#updating-the-document class=self-link></a></h5>

  <p>To <dfn id=update-document-for-history-step-application>update document for history step application</dfn> given a <code id=updating-the-document:document><a href=dom.html#document>Document</a></code>
  <var>document</var>, a <a href=#session-history-entry id=updating-the-document:session-history-entry>session history entry</a> <var>entry</var>, a boolean
  <var>doNotReactivate</var>, integers <var>scriptHistoryLength</var> and
  <var>scriptHistoryIndex</var>, <code id=updating-the-document:navigationtype><a href=nav-history-apis.html#navigationtype>NavigationType</a></code>-or-null <var>navigationType</var>, an
  optional <a id=updating-the-document:list href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a> of <a href=#session-history-entry id=updating-the-document:session-history-entry-2>session history entries</a>
  <var>entriesForNavigationAPI</var>, and an optional <a href=#session-history-entry id=updating-the-document:session-history-entry-3>session history entry</a>
  <var>previousEntryForActivation</var>:</p>

  <ol><li><p>Let <var>documentIsNew</var> be true if <var>document</var>'s <a href=#latest-entry id=updating-the-document:latest-entry>latest entry</a>
   is null; otherwise false.<li><p>Let <var>documentsEntryChanged</var> be true if <var>document</var>'s <a href=#latest-entry id=updating-the-document:latest-entry-2>latest
   entry</a> is not <var>entry</var>; otherwise false.<li><p>Set <var>document</var>'s <a href=nav-history-apis.html#doc-history id=updating-the-document:doc-history>history object</a>'s <a href=nav-history-apis.html#concept-history-index id=updating-the-document:concept-history-index>index</a> to <var>scriptHistoryIndex</var>.<li><p>Set <var>document</var>'s <a href=nav-history-apis.html#doc-history id=updating-the-document:doc-history-2>history object</a>'s <a href=nav-history-apis.html#concept-history-length id=updating-the-document:concept-history-length>length</a> to <var>scriptHistoryLength</var>.<li><p>Let <var>navigation</var> be <var>history</var>'s <a id=updating-the-document:concept-relevant-global href=webappapis.html#concept-relevant-global>relevant global object</a>'s
   <a href=nav-history-apis.html#window-navigation-api id=updating-the-document:window-navigation-api>navigation API</a>.<li>
    <p>If <var>documentsEntryChanged</var> is true, then:</p>

    <ol><li><p>Let <var>oldURL</var> be <var>document</var>'s <a href=#latest-entry id=updating-the-document:latest-entry-3>latest entry</a>'s <a href=#she-url id=updating-the-document:she-url>URL</a>.<li><p>Set <var>document</var>'s <a href=#latest-entry id=updating-the-document:latest-entry-4>latest entry</a> to <var>entry</var>.<li><p><a href=#restore-the-history-object-state id=updating-the-document:restore-the-history-object-state>Restore the history object state</a> given <var>document</var> and
     <var>entry</var>.<li>
      <p>If <var>documentIsNew</var> is false, then:</p>

      <ol><li><p><a id=updating-the-document:assert href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>navigationType</var> is not null.<li><p><a id=updating-the-document:update-the-navigation-api-entries-for-a-same-document-navigation href=nav-history-apis.html#update-the-navigation-api-entries-for-a-same-document-navigation>Update the navigation API entries for a same-document navigation</a> given
       <var>navigation</var>, <var>entry</var>, and <var>navigationType</var>.<li><p><a href=https://dom.spec.whatwg.org/#concept-event-fire id=updating-the-document:concept-event-fire data-x-internal=concept-event-fire>Fire an event</a> named <code id=updating-the-document:event-popstate><a href=indices.html#event-popstate>popstate</a></code> at <var>document</var>'s <a id=updating-the-document:concept-relevant-global-2 href=webappapis.html#concept-relevant-global>relevant global
       object</a>, using <code id=updating-the-document:popstateevent><a href=nav-history-apis.html#popstateevent>PopStateEvent</a></code>, with the <code id=updating-the-document:dom-popstateevent-state><a href=nav-history-apis.html#dom-popstateevent-state>state</a></code> attribute initialized to <var>document</var>'s
       <a href=nav-history-apis.html#doc-history id=updating-the-document:doc-history-3>history object</a>'s <a href=nav-history-apis.html#concept-history-state id=updating-the-document:concept-history-state>state</a> and <code id=updating-the-document:dom-popstateevent-hasuavisualtransition><a href=nav-history-apis.html#dom-popstateevent-hasuavisualtransition>hasUAVisualTransition</a></code> initialized to
       true if a visual transition, to display a cached rendered state of the <a href=#latest-entry id=updating-the-document:latest-entry-5>latest
       entry</a>, was done by the user agent.</p>

       <li><p><a href=#restore-persisted-state id=updating-the-document:restore-persisted-state>Restore persisted state</a> given <var>entry</var>.<li><p>If <var>oldURL</var>'s <a href=https://url.spec.whatwg.org/#concept-url-fragment id=updating-the-document:concept-url-fragment data-x-internal=concept-url-fragment>fragment</a> is not
       equal to <var>entry</var>'s <a href=#she-url id=updating-the-document:she-url-2>URL</a>'s <a href=https://url.spec.whatwg.org/#concept-url-fragment id=updating-the-document:concept-url-fragment-2 data-x-internal=concept-url-fragment>fragment</a>, then <a id=updating-the-document:queue-a-global-task href=webappapis.html#queue-a-global-task>queue a global task</a> on the
       <a id=updating-the-document:dom-manipulation-task-source href=webappapis.html#dom-manipulation-task-source>DOM manipulation task source</a> given <var>document</var>'s <a id=updating-the-document:concept-relevant-global-3 href=webappapis.html#concept-relevant-global>relevant global
       object</a> to <a href=https://dom.spec.whatwg.org/#concept-event-fire id=updating-the-document:concept-event-fire-2 data-x-internal=concept-event-fire>fire an event</a> named <code id=updating-the-document:event-hashchange><a href=indices.html#event-hashchange>hashchange</a></code> at <var>document</var>'s <a id=updating-the-document:concept-relevant-global-4 href=webappapis.html#concept-relevant-global>relevant global
       object</a>, using <code id=updating-the-document:hashchangeevent><a href=nav-history-apis.html#hashchangeevent>HashChangeEvent</a></code>, with the <code id=updating-the-document:dom-hashchangeevent-oldurl><a href=nav-history-apis.html#dom-hashchangeevent-oldurl>oldURL</a></code> attribute initialized to the <a href=https://url.spec.whatwg.org/#concept-url-serializer id=updating-the-document:concept-url-serializer data-x-internal=concept-url-serializer>serialization</a> of <var>oldURL</var> and the <code id=updating-the-document:dom-hashchangeevent-newurl><a href=nav-history-apis.html#dom-hashchangeevent-newurl>newURL</a></code> attribute initialized to the <a href=https://url.spec.whatwg.org/#concept-url-serializer id=updating-the-document:concept-url-serializer-2 data-x-internal=concept-url-serializer>serialization</a> of <var>entry</var>'s <a href=#she-url id=updating-the-document:she-url-3>URL</a>.</ol>
     <li>
      <p>Otherwise:</p>

      <ol><li><p><a id=updating-the-document:assert-2 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>entriesForNavigationAPI</var> is given.<li><p><a href=#restore-persisted-state id=updating-the-document:restore-persisted-state-2>Restore persisted state</a> given <var>entry</var>.<li><p><a id=updating-the-document:initialize-the-navigation-api-entries-for-a-new-document href=nav-history-apis.html#initialize-the-navigation-api-entries-for-a-new-document>Initialize the navigation API entries for a new document</a> given
       <var>navigation</var>, <var>entriesForNavigationAPI</var>, and <var>entry</var>.</ol>
     </ol>
   <li>
    <p>If all the following are true:</p>

    <ul><li><p><var>previousEntryForActivation</var> is given;<li><p><var>navigationType</var> is non-null; and<li><p><var>navigationType</var> is "<code id=updating-the-document:dom-navigationtype-reload><a href=nav-history-apis.html#dom-navigationtype-reload>reload</a></code>" or
     <var>previousEntryForActivation</var>'s <a href=#she-document id=updating-the-document:she-document>document</a> is not
     <var>document</var>,</ul>

    <p>then:</p>

    <ol><li><p>If <var>navigation</var>'s <a href=nav-history-apis.html#navigation-activation id=updating-the-document:navigation-activation>activation</a> is null, then set <var>navigation</var>'s
     <a href=nav-history-apis.html#navigation-activation id=updating-the-document:navigation-activation-2>activation</a> to a new
     <code id=updating-the-document:navigationactivation><a href=nav-history-apis.html#navigationactivation>NavigationActivation</a></code> object in <var>navigation</var>'s
     <a href=webappapis.html#concept-relevant-realm id=updating-the-document:concept-relevant-realm>relevant realm</a>.<li><p>Let <var>previousEntryIndex</var> be the result of
     <a id=updating-the-document:getting-the-navigation-api-entry-index href=nav-history-apis.html#getting-the-navigation-api-entry-index>getting the navigation API entry index</a> of <var>previousEntryForActivation</var>
     within <var>navigation</var>.<li><p>If <var>previousEntryIndex</var> is non-negative, then set <var>activation</var>'s
     <a href=nav-history-apis.html#nav-activation-old-entry id=updating-the-document:nav-activation-old-entry>old entry</a> to <var>navigation</var>'s <a href=nav-history-apis.html#navigation-entry-list id=updating-the-document:navigation-entry-list>entry list</a>[<var>previousEntryIndex</var>].<li>
      <p>Otherwise, if all the following are true:</p>

      <ul><li><p><var>navigationType</var> is "<code id=updating-the-document:dom-navigationtype-replace><a href=nav-history-apis.html#dom-navigationtype-replace>replace</a></code>";<li><p><var>previousEntryForActivation</var>'s
       <a href=#she-document-state id=updating-the-document:she-document-state>document state</a>'s <a href=#document-state-origin id=updating-the-document:document-state-origin>origin</a> is <a id=updating-the-document:same-origin href=browsers.html#same-origin>same origin</a> with
       <var>document</var>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=updating-the-document:concept-document-origin data-x-internal=concept-document-origin>origin</a>; and<li><p><var>previousEntryForActivation</var>'s <a href=#she-document id=updating-the-document:she-document-2>document</a>'s
       <a href=dom.html#is-initial-about:blank id=updating-the-document:is-initial-about:blank>initial <code>about:blank</code></a> is
       false,</ul>

      <p>then set <var>activation</var>'s <a href=nav-history-apis.html#nav-activation-old-entry id=updating-the-document:nav-activation-old-entry-2>old entry</a>
      to a new <code id=updating-the-document:navigationhistoryentry><a href=nav-history-apis.html#navigationhistoryentry>NavigationHistoryEntry</a></code> in <var>navigation</var>'s <a href=webappapis.html#concept-relevant-realm id=updating-the-document:concept-relevant-realm-2>relevant realm</a>, whose <a href=nav-history-apis.html#nhe-she id=updating-the-document:nhe-she>session history entry</a> is
      <var>previousEntryForActivation</var>.</p>
     <li><p>Set <var>activation</var>'s <a href=nav-history-apis.html#nav-activation-new-entry id=updating-the-document:nav-activation-new-entry>new entry</a> to
     <var>navigation</var>'s <a href=nav-history-apis.html#navigation-current-entry id=updating-the-document:navigation-current-entry>current entry</a>.<li><p>Set <var>activation</var>'s <a href=nav-history-apis.html#nav-activation-navigation-type id=updating-the-document:nav-activation-navigation-type>navigation type</a> to
     <var>navigationType</var>.</ol>
   <li>
    <p>If <var>documentIsNew</var> is true, then:</p>

    <ol><li><p><a id=updating-the-document:assert-3 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>document</var>'s <a href=dom.html#concept-document-navigation-id id=updating-the-document:concept-document-navigation-id>during-loading navigation ID for WebDriver BiDi</a>
     is not null.<li><p>Invoke <a id=updating-the-document:webdriver-bidi-navigation-committed href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-navigation-committed data-x-internal=webdriver-bidi-navigation-committed>WebDriver BiDi navigation committed</a> with <var>navigable</var> and a
     new <a id=updating-the-document:webdriver-bidi-navigation-status href=https://w3c.github.io/webdriver-bidi/#webdriver-bidi-navigation-status data-x-internal=webdriver-bidi-navigation-status>WebDriver BiDi navigation status</a> whose <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-id id=updating-the-document:navigation-status-id data-x-internal=navigation-status-id>id</a> is <var>document</var>'s <a href=dom.html#concept-document-navigation-id id=updating-the-document:concept-document-navigation-id-2>during-loading navigation ID for WebDriver BiDi</a>,
     <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-status id=updating-the-document:navigation-status-status data-x-internal=navigation-status-status>status</a> is "<code id=updating-the-document:navigation-status-committed><a data-x-internal=navigation-status-committed href=https://w3c.github.io/webdriver-bidi/#navigation-status-committed>committed</a></code>", and <a href=https://w3c.github.io/webdriver-bidi/#navigation-status-url id=updating-the-document:navigation-status-url data-x-internal=navigation-status-url>url</a> is <var>document</var>'s <a href=https://dom.spec.whatwg.org/#concept-document-url id="updating-the-document:the-document's-address" data-x-internal="the-document's-address">URL</a>.<li><p><a href=#try-to-scroll-to-the-fragment id=updating-the-document:try-to-scroll-to-the-fragment>Try to scroll to the fragment</a> for <var>document</var>.<li><p>At this point <dfn id=scripts-may-run-for-the-newly-created-document>scripts may run for the newly-created document</dfn>
     <var>document</var>.</ol>
   <li>
    <p>Otherwise, if <var>documentsEntryChanged</var> is false and <var>doNotReactivate</var> is
    false, then:</p>

    <ol><li><p><a id=updating-the-document:assert-4 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>entriesForNavigationAPI</var> is given.<li><p><a href=#reactivate-a-document id=updating-the-document:reactivate-a-document>Reactivate</a> <var>document</var> given
     <var>entry</var> and <var>entriesForNavigationAPI</var>.</p>
    </ol>

    <p class=note><var>documentsEntryChanged</var> can be false for one of two reasons: either we
    are restoring from <a href=#note-bfcache>bfcache</a>, or we are asynchronously finishing up a
    synchronous navigation which already synchronously set <var>document</var>'s <a href=#latest-entry id=updating-the-document:latest-entry-6>latest
    entry</a>. The <var>doNotReactivate</var> argument distinguishes between these two
    cases.</p>
   </ol>

  <p>To <dfn id=restore-the-history-object-state>restore the history object state</dfn> given <code id=updating-the-document:document-2><a href=dom.html#document>Document</a></code>
  <var>document</var> and <a href=#session-history-entry id=updating-the-document:session-history-entry-4>session history entry</a> <var>entry</var>:</p>

  <ol><li><p>Let <var>targetRealm</var> be <var>document</var>'s <a href=webappapis.html#concept-relevant-realm id=updating-the-document:concept-relevant-realm-3>relevant realm</a>.<li><p>Let <var>state</var> be <a id=updating-the-document:structureddeserialize href=structured-data.html#structureddeserialize>StructuredDeserialize</a>(<var>entry</var>'s <a href=#she-classic-history-api-state id=updating-the-document:she-classic-history-api-state>classic history API state</a>, <var>targetRealm</var>).
   If this throws an exception, catch it and let <var>state</var> be null.<li><p>Set <var>document</var>'s <a href=nav-history-apis.html#doc-history id=updating-the-document:doc-history-4>history object</a>'s <a href=nav-history-apis.html#concept-history-state id=updating-the-document:concept-history-state-2>state</a> to <var>state</var>.</ol>

  <p>To <dfn id=make-active>make active</dfn> a <code id=updating-the-document:document-3><a href=dom.html#document>Document</a></code> <var>document</var>:</p>

  <ol><li><p>Let <var>window</var> be <var>document</var>'s <a id=updating-the-document:concept-relevant-global-5 href=webappapis.html#concept-relevant-global>relevant global
   object</a>.<li><p>Set <var>document</var>'s <a href=document-sequences.html#concept-document-bc id=updating-the-document:concept-document-bc>browsing context</a>'s
   <code id=updating-the-document:windowproxy><a href=nav-history-apis.html#windowproxy>WindowProxy</a></code>'s <a href=nav-history-apis.html#concept-windowproxy-window id=updating-the-document:concept-windowproxy-window>[[Window]]</a> internal
   slot value to <var>window</var>.<li><p>Set <var>document</var>'s <a id=updating-the-document:visibility-state href=interaction.html#visibility-state>visibility state</a> to <var>document</var>'s
   <a id=updating-the-document:node-navigable href=document-sequences.html#node-navigable>node navigable</a>'s <a href=document-sequences.html#nav-traversable id=updating-the-document:nav-traversable>traversable navigable</a>'s
   <a id=updating-the-document:system-visibility-state href=document-sequences.html#system-visibility-state>system visibility state</a>.<li><p><a href=https://w3c.github.io/performance-timeline/#queue-a-performanceentry id=updating-the-document:queue-a-performance-entry data-x-internal=queue-a-performance-entry>Queue</a> a new
   <code id=updating-the-document:visibilitystateentry><a href=interaction.html#visibilitystateentry>VisibilityStateEntry</a></code> whose <a href=interaction.html#visibilitystateentry-state id=updating-the-document:visibilitystateentry-state>visibility
   state</a> is <var>document</var>'s <a id=updating-the-document:visibility-state-2 href=interaction.html#visibility-state>visibility state</a> and whose <a href=interaction.html#visibilitystateentry-timestamp id=updating-the-document:visibilitystateentry-timestamp>timestamp</a> is zero.<li><p>Set <var>window</var>'s <a id=updating-the-document:relevant-settings-object href=webappapis.html#relevant-settings-object>relevant settings object</a>'s <a href=webappapis.html#concept-environment-execution-ready-flag id=updating-the-document:concept-environment-execution-ready-flag>execution ready flag</a>.</ol>

  <p>To <dfn data-dfn-for=Document id=reactivate-a-document data-export="">reactivate</dfn> a
  <code id=updating-the-document:document-4><a href=dom.html#document>Document</a></code> <var>document</var> given a <a href=#session-history-entry id=updating-the-document:session-history-entry-5>session history entry</a>
  <var>reactivatedEntry</var> and a <a id=updating-the-document:list-2 href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a> of <a href=#session-history-entry id=updating-the-document:session-history-entry-6>session history entries</a> <var>entriesForNavigationAPI</var>:</p>

  <p class=note>This algorithm updates <var>document</var> after it has come out of <a href=#note-bfcache>bfcache</a>, i.e., after it has been made <a id=updating-the-document:fully-active href=document-sequences.html#fully-active>fully active</a>
  again. Other specifications that want to watch for this change to the <a id=updating-the-document:fully-active-2 href=document-sequences.html#fully-active>fully
  active</a> state are encouraged to add steps into this algorithm, so that the ordering
  of events that happen in effect of the change is clear.</p>

  <ol><li id=history-autocomplete><p><a href=https://infra.spec.whatwg.org/#list-iterate id=updating-the-document:list-iterate data-x-internal=list-iterate>For each</a>
   <var>formControl</var> of form controls in <var>document</var> with an <a id=updating-the-document:autofill-field-name href=form-control-infrastructure.html#autofill-field-name>autofill field
   name</a> of "<code id=updating-the-document:attr-fe-autocomplete-off><a href=form-control-infrastructure.html#attr-fe-autocomplete-off>off</a></code>", invoke the <a href=form-control-infrastructure.html#concept-form-reset-control id=updating-the-document:concept-form-reset-control>reset algorithm</a> for <var>formControl</var>.<li>
    <p>If <var>document</var>'s <a id=updating-the-document:suspended-timer-handles href=document-lifecycle.html#suspended-timer-handles>suspended timer handles</a> is not <a href=https://infra.spec.whatwg.org/#list-is-empty id=updating-the-document:list-is-empty data-x-internal=list-is-empty>empty</a>:</p>

    <ol><li><p><a id=updating-the-document:assert-5 href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>document</var>'s <a id=updating-the-document:suspension-time href=document-lifecycle.html#suspension-time>suspension time</a> is not
     zero.<li><p>Let <var>suspendDuration</var> be the <a id=updating-the-document:current-high-resolution-time href=https://w3c.github.io/hr-time/#dfn-current-high-resolution-time data-x-internal=current-high-resolution-time>current high resolution time</a> minus
     <var>document</var>'s <a id=updating-the-document:suspension-time-2 href=document-lifecycle.html#suspension-time>suspension time</a>.<li><p>Let <var>activeTimers</var> be <var>document</var>'s <a id=updating-the-document:concept-relevant-global-6 href=webappapis.html#concept-relevant-global>relevant global
     object</a>'s <a id=updating-the-document:map-of-active-timers href=timers-and-user-prompts.html#map-of-active-timers>map of active timers</a>.<li><p>For each <var>handle</var> in <var>document</var>'s <a id=updating-the-document:suspended-timer-handles-2 href=document-lifecycle.html#suspended-timer-handles>suspended timer
     handles</a>, if <var>activeTimers</var>[<var>handle</var>] <a href=https://infra.spec.whatwg.org/#map-exists id=updating-the-document:map-exists data-x-internal=map-exists>exists</a>, then increase <var>activeTimers</var>[<var>handle</var>] by
     <var>suspendDuration</var>.</ol>
   <li><p><a id=updating-the-document:update-the-navigation-api-entries-for-reactivation href=nav-history-apis.html#update-the-navigation-api-entries-for-reactivation>Update the navigation API entries for reactivation</a> given
   <var>document</var>'s <a id=updating-the-document:concept-relevant-global-7 href=webappapis.html#concept-relevant-global>relevant global object</a>'s <a href=nav-history-apis.html#window-navigation-api id=updating-the-document:window-navigation-api-2>navigation API</a>, <var>entriesForNavigationAPI</var>, and
   <var>reactivatedEntry</var>.<li>
    <p>If <var>document</var>'s <a id=updating-the-document:current-document-readiness href=dom.html#current-document-readiness>current document readiness</a> is "<code>complete</code>", and <var>document</var>'s <a id=updating-the-document:page-showing href=document-lifecycle.html#page-showing>page showing</a> is false:</p>

    <ol><li><p>Set <var>document</var>'s <a id=updating-the-document:page-showing-2 href=document-lifecycle.html#page-showing>page showing</a> to true.<li><p>Set <var>document</var>'s <a href=#has-been-revealed id=updating-the-document:has-been-revealed>has been revealed</a> to false.</p>

     <li><p><a id=updating-the-document:update-the-visibility-state href=interaction.html#update-the-visibility-state>Update the visibility state</a> of <var>document</var> to "<code>visible</code>".<li><p><a id=updating-the-document:fire-a-page-transition-event href=nav-history-apis.html#fire-a-page-transition-event>Fire a page transition event</a> named <code id=updating-the-document:event-pageshow><a href=indices.html#event-pageshow>pageshow</a></code> at <var>document</var>'s <a id=updating-the-document:concept-relevant-global-8 href=webappapis.html#concept-relevant-global>relevant global
     object</a> with true.</ol>

    
   </ol>

  <p>To <dfn id=try-to-scroll-to-the-fragment>try to scroll to the fragment</dfn> for a <code id=updating-the-document:document-5><a href=dom.html#document>Document</a></code> <var>document</var>,
  perform the following steps <a id=updating-the-document:in-parallel href=infrastructure.html#in-parallel>in parallel</a>:</p>

  <ol><li><p>Wait for an <a id=updating-the-document:implementation-defined href=https://infra.spec.whatwg.org/#implementation-defined data-x-internal=implementation-defined>implementation-defined</a> amount of time. (This is intended to allow
   the user agent to optimize the user experience in the face of performance concerns.)<li>
    <p><a id=updating-the-document:queue-a-global-task-2 href=webappapis.html#queue-a-global-task>Queue a global task</a> on the <a id=updating-the-document:navigation-and-traversal-task-source href=webappapis.html#navigation-and-traversal-task-source>navigation and traversal task source</a>
    given <var>document</var>'s <a id=updating-the-document:concept-relevant-global-9 href=webappapis.html#concept-relevant-global>relevant global object</a> to run these steps:</p>

    <ol><li><p>If <var>document</var> has no parser, or its parser has <a href=parsing.html#stop-parsing id=updating-the-document:stop-parsing>stopped parsing</a>, or the user agent has reason to believe the user is no longer
     interested in scrolling to the <a href=https://url.spec.whatwg.org/#concept-url-fragment id=updating-the-document:concept-url-fragment-3 data-x-internal=concept-url-fragment>fragment</a>, then abort
     these steps.<li><p><a href=#scroll-to-the-fragment-identifier id=updating-the-document:scroll-to-the-fragment-identifier>Scroll to the fragment</a> given <var>document</var>.<li><p>If <var>document</var>'s <a href=#the-indicated-part-of-the-document id=updating-the-document:the-indicated-part-of-the-document>indicated part</a> is still null, then <a href=#try-to-scroll-to-the-fragment id=updating-the-document:try-to-scroll-to-the-fragment-2>try to
     scroll to the fragment</a> for <var>document</var>.</ol>
   </ol>

  <p>To <dfn id=make-document-unsalvageable data-export="">make document unsalvageable</dfn>, given a <code id=updating-the-document:document-6><a href=dom.html#document>Document</a></code>
  <var>document</var> and a string <var>reason</var>:</p>

  <ol><li><p>Let <var>details</var> be a new <a href=nav-history-apis.html#nrr-details-struct id=updating-the-document:nrr-details-struct>not restored reason details</a> whose <a href=nav-history-apis.html#nrr-details-reason id=updating-the-document:nrr-details-reason>reason</a> is <var>reason</var>.<li><p><a href=https://infra.spec.whatwg.org/#set-append id=updating-the-document:set-append data-x-internal=set-append>Append</a> <var>details</var> to <var>document</var>'s
   <a href=dom.html#concept-document-bfcache-blocking-details id=updating-the-document:concept-document-bfcache-blocking-details>bfcache blocking details</a>.<li><p>Set <var>document</var>'s <i id=updating-the-document:concept-document-salvageable><a href=document-lifecycle.html#concept-document-salvageable>salvageable</a></i>
   state to false.</ol>

  <p>To <dfn id=build-not-restored-reasons-for-document-state>build not restored reasons for document state</dfn> given <code id=updating-the-document:document-7><a href=dom.html#document>Document</a></code>
  <var>document</var>:</p>

  <ol><li><p>Let <var>notRestoredReasonsForDocument</var> be a new <a href=nav-history-apis.html#nrr-struct id=updating-the-document:nrr-struct>not restored reasons</a>.<li><p>Set <var>notRestoredReasonsForDocument</var>'s <a href=nav-history-apis.html#nrr-url id=updating-the-document:nrr-url>URL</a> to
   <var>document</var>'s <a href=https://dom.spec.whatwg.org/#concept-document-url id="updating-the-document:the-document's-address-2" data-x-internal="the-document's-address">URL</a>.<li><p>Let <var>container</var> be <var>document</var>'s <a id=updating-the-document:node-navigable-2 href=document-sequences.html#node-navigable>node navigable</a>'s <a href=document-sequences.html#nav-container id=updating-the-document:nav-container>container</a>.<li>
    <p>If <var>container</var> is an <code id=updating-the-document:the-iframe-element><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code> element:</p>

    <ol><li><p>Let <var>src</var> be the empty string.<li>
      <p>If <var>container</var> has a <code id=updating-the-document:dom-iframe-src><a href=iframe-embed-object.html#dom-iframe-src>src</a></code> attribute:</p>

      <ol><li><p>Let <var>src</var> be the result of <a id=updating-the-document:encoding-parsing-and-serializing-a-url href=urls-and-fetching.html#encoding-parsing-and-serializing-a-url>encoding-parsing-and-serializing a
       URL</a> given <var>container</var>'s <code id=updating-the-document:attr-iframe-src><a href=iframe-embed-object.html#attr-iframe-src>src</a></code> attribute's
       value, relative to <var>container</var>'s <a id=updating-the-document:node-document href=https://dom.spec.whatwg.org/#concept-node-document data-x-internal=node-document>node document</a>.<li><p>If <var>src</var> is failure, then set <var>src</var> to <var>container</var>'s <code id=updating-the-document:attr-iframe-src-2><a href=iframe-embed-object.html#attr-iframe-src>src</a></code> attribute's value.</ol>
     <li><p>Set <var>notRestoredReasonsForDocument</var>'s <a href=nav-history-apis.html#nrr-src id=updating-the-document:nrr-src>src</a> to
     <var>src</var>.<li><p>Set <var>notRestoredReasonsForDocument</var>'s <a href=nav-history-apis.html#nrr-id id=updating-the-document:nrr-id>id</a> to
     <var>container</var>'s <code id=updating-the-document:the-id-attribute><a href=dom.html#the-id-attribute>id</a></code> attribute's value, or the empty string
     if it has no such attribute.<li><p>Set <var>notRestoredReasonsForDocument</var>'s <a href=nav-history-apis.html#nrr-name id=updating-the-document:nrr-name>name</a> to
     <var>container</var>'s <code id=updating-the-document:attr-iframe-name><a href=iframe-embed-object.html#attr-iframe-name>name</a></code> attribute's value, or the
     empty string if it has no such attribute.</ol>
   <li><p>Set <var>notRestoredReasonsForDocument</var>'s <a href=nav-history-apis.html#nrr-reasons id=updating-the-document:nrr-reasons>reasons</a>
   to a <a href=https://infra.spec.whatwg.org/#list-clone id=updating-the-document:list-clone data-x-internal=list-clone>clone</a> of <var>document</var>'s <a href=dom.html#concept-document-bfcache-blocking-details id=updating-the-document:concept-document-bfcache-blocking-details-2>bfcache blocking details</a>.<li>
    <p><a href=https://infra.spec.whatwg.org/#list-iterate id=updating-the-document:list-iterate-2 data-x-internal=list-iterate>For each</a> <var>navigable</var> of <var>document</var>'s
    <a href=document-sequences.html#document-tree-child-navigables id=updating-the-document:document-tree-child-navigables>document-tree child navigables</a>:</p>

    <ol><li><p>Let <var>childDocument</var> be <var>navigable</var>'s <a href=document-sequences.html#nav-document id=updating-the-document:nav-document>active document</a>.<li><p><a href=#build-not-restored-reasons-for-document-state id=updating-the-document:build-not-restored-reasons-for-document-state>Build not restored reasons for document state</a> given
     <var>childDocument</var>.<li><p><a href=https://infra.spec.whatwg.org/#list-append id=updating-the-document:list-append data-x-internal=list-append>Append</a> <var>childDocument</var>'s <a href=nav-history-apis.html#concept-document-nrr id=updating-the-document:concept-document-nrr>not restored reasons</a> to
     <var>notRestoredReasonsForDocument</var>'s <a href=nav-history-apis.html#nrr-children id=updating-the-document:nrr-children>children</a>.</ol>
   <li><p>Set <var>document</var>'s <a id=updating-the-document:node-navigable-3 href=document-sequences.html#node-navigable>node navigable</a>'s <a href=document-sequences.html#nav-active-history-entry id=updating-the-document:nav-active-history-entry>active session history entry</a>'s <a href=#she-document-state id=updating-the-document:she-document-state-2>document state</a>'s <a href=#document-state-not-restored-reasons id=updating-the-document:document-state-not-restored-reasons>not restored reasons</a> to
   <var>notRestoredReasonsForDocument</var>.</ol>

 <p>To <dfn id=build-not-restored-reasons-for-a-top-level-traversable-and-its-descendants>build not restored reasons for a top-level traversable and its descendants</dfn>
 given <a id=updating-the-document:top-level-traversable href=document-sequences.html#top-level-traversable>top-level traversable</a> <var>topLevelTraversable</var>:
 <ol><li><p><a href=#build-not-restored-reasons-for-document-state id=updating-the-document:build-not-restored-reasons-for-document-state-2>Build not restored reasons for document state</a> given
  <var>topLevelTraversable</var>'s <a href=document-sequences.html#nav-document id=updating-the-document:nav-document-2>active document</a>.<li><p>Let <var>crossOriginDescendants</var> be an empty <a id=updating-the-document:list-3 href=https://infra.spec.whatwg.org/#list data-x-internal=list>list</a>.<li>
   <p><a href=https://infra.spec.whatwg.org/#list-iterate id=updating-the-document:list-iterate-3 data-x-internal=list-iterate>For each</a> <var>childNavigable</var> of
   <var>topLevelTraversable</var>'s <a href=document-sequences.html#nav-document id=updating-the-document:nav-document-3>active document</a>'s
   <a id=updating-the-document:descendant-navigables href=document-sequences.html#descendant-navigables>descendant navigables</a>:</p>
   <ol><li><p>If <var>childNavigable</var>'s <a href=document-sequences.html#nav-document id=updating-the-document:nav-document-4>active document</a>'s
    <a href=https://dom.spec.whatwg.org/#concept-document-origin id=updating-the-document:concept-document-origin-2 data-x-internal=concept-document-origin>origin</a> is not <a id=updating-the-document:same-origin-2 href=browsers.html#same-origin>same origin</a> with
    <var>topLevelTraversable</var>'s <a href=document-sequences.html#nav-document id=updating-the-document:nav-document-5>active document</a>'s <a href=https://dom.spec.whatwg.org/#concept-document-origin id=updating-the-document:concept-document-origin-3 data-x-internal=concept-document-origin>origin</a>, then <a href=https://infra.spec.whatwg.org/#list-append id=updating-the-document:list-append-2 data-x-internal=list-append>append</a>
    <var>childNavigable</var> to <var>crossOriginDescendants</var>.</ol>
  <li><p>Let <var>crossOriginDescendantsPreventsBfcache</var> be false.<li>
   <p><a href=https://infra.spec.whatwg.org/#list-iterate id=updating-the-document:list-iterate-4 data-x-internal=list-iterate>For each</a> <var>crossOriginNavigable</var> of
   <var>crossOriginDescendants</var>:</p>

   <ol><li><p>Let <var>reasonsForCrossOriginChild</var> be <var>crossOriginNavigable</var>'s <a href=document-sequences.html#nav-document id=updating-the-document:nav-document-6>active document</a>'s <a href=#document-state-2 id=updating-the-document:document-state-2>document state</a>'s <a href=#document-state-not-restored-reasons id=updating-the-document:document-state-not-restored-reasons-2>not restored reasons</a>.<li><p>If <var>reasonsForCrossOriginChild</var>'s <a href=nav-history-apis.html#nrr-reasons id=updating-the-document:nrr-reasons-2>reasons</a>
    is not empty, set <var>crossOriginDescendantsPreventsBfcache</var> to true.<li><p>Set <var>reasonsForCrossOriginChild</var>'s <a href=nav-history-apis.html#nrr-url id=updating-the-document:nrr-url-2>URL</a> to
    null.<li><p>Set <var>reasonsForCrossOriginChild</var>'s <a href=nav-history-apis.html#nrr-reasons id=updating-the-document:nrr-reasons-3>reasons</a>
    to null.<li><p>Set <var>reasonsForCrossOriginChild</var>'s <a href=nav-history-apis.html#nrr-children id=updating-the-document:nrr-children-2>children</a>
    to null.</ol>
  <li><p>If <var>crossOriginDescendantsPreventsBfcache</var> is true, <a href=#make-document-unsalvageable id=updating-the-document:make-document-unsalvageable>make document
  unsalvageable</a> given <var>topLevelTraversable</var>'s <a href=document-sequences.html#nav-document id=updating-the-document:nav-document-7>active document</a> and "<code id=updating-the-document:blocking-masked><a href=nav-history-apis.html#blocking-masked>masked</a></code>".</ol>

  <h5 id=revealing-the-document><span class=secno>7.4.6.3</span> Revealing the document<a href=#revealing-the-document class=self-link></a></h5>

  <p>A <code id=revealing-the-document:document><a href=dom.html#document>Document</a></code> has a boolean <dfn id=has-been-revealed>has been revealed</dfn>, initially false. It is used
  to ensure that the <code id=revealing-the-document:event-pagereveal><a href=indices.html#event-pagereveal>pagereveal</a></code> event is fired once for each
  activation of the <code id=revealing-the-document:document-2><a href=dom.html#document>Document</a></code> (once when it's rendered initially, and once for each
  <a href=#reactivate-a-document id=revealing-the-document:reactivate-a-document>reactivation</a>).</p>

  <p>To <dfn id=reveal>reveal</dfn> a <code id=revealing-the-document:document-3><a href=dom.html#document>Document</a></code> <var>document</var>:</p>

  <ol><li><p>If <var>document</var>'s <a href=#has-been-revealed id=revealing-the-document:has-been-revealed>has been revealed</a> is true, then return.<li><p>Set <var>document</var>'s <a href=#has-been-revealed id=revealing-the-document:has-been-revealed-2>has been revealed</a> to true.<li><p>Let <var>transition</var> be the result of
   <a id=revealing-the-document:resolving-inbound-cross-document-view-transition href=https://drafts.csswg.org/css-view-transitions-2/#resolve-inbound-cross-document-view-transition data-x-internal=resolving-inbound-cross-document-view-transition>resolving inbound cross-document view-transition</a> for <var>document</var>.<li><p><a href=https://dom.spec.whatwg.org/#concept-event-fire id=revealing-the-document:concept-event-fire data-x-internal=concept-event-fire>Fire an event</a> named
   <code id=revealing-the-document:event-pagereveal-2><a href=indices.html#event-pagereveal>pagereveal</a></code> at <var>document</var>'s
   <a id=revealing-the-document:concept-relevant-global href=webappapis.html#concept-relevant-global>relevant global object</a>, using <code id=revealing-the-document:pagerevealevent><a href=nav-history-apis.html#pagerevealevent>PageRevealEvent</a></code> with its <code id=revealing-the-document:dom-pagerevealevent-viewtransition><a href=nav-history-apis.html#dom-pagerevealevent-viewtransition>viewTransition</a></code> set to
   <var>transition</var>.<li>
    <p>If <var>transition</var> is not null, then:</p>

    <ol><li><p><a id=revealing-the-document:prepare-to-run-script href=webappapis.html#prepare-to-run-script>Prepare to run script</a> given <var>document</var>'s
     <a id=revealing-the-document:relevant-settings-object href=webappapis.html#relevant-settings-object>relevant settings object</a>.<li><p><a href=https://drafts.csswg.org/css-view-transitions/#activate-view-transition id=revealing-the-document:activate-view-transition data-x-internal=activate-view-transition>Activate</a> <var>transition</var>.<li><p><a id=revealing-the-document:clean-up-after-running-script href=webappapis.html#clean-up-after-running-script>Clean up after running script</a> given <var>document</var>'s
     <a id=revealing-the-document:relevant-settings-object-2 href=webappapis.html#relevant-settings-object>relevant settings object</a>.</ol>

    <p class=note>Activating a view transition might resolve/reject promises, so by wrapping the
    activation with prepare/cleanup we ensure those promises are handled before the next rendering
    step.</p>
   </ol>

  <p class=note>Though <code id=revealing-the-document:event-pagereveal-3><a href=indices.html#event-pagereveal>pagereveal</a></code> is guaranteed to be fired
  during the first <a id=revealing-the-document:update-the-rendering href=webappapis.html#update-the-rendering>update the rendering</a> step that displays an up-to-date version of the
  page, user agents are free to display a cached frame of the page before firing it. This prevents
  the presence of a <code id=revealing-the-document:event-pagereveal-4><a href=indices.html#event-pagereveal>pagereveal</a></code> handler from delaying the
  presentation of such cached frame.</p>


  <h5 id=scrolling-to-a-fragment><span class=secno>7.4.6.4</span> Scrolling to a fragment<a href=#scrolling-to-a-fragment class=self-link></a></h5>

  <p>To <dfn id=scroll-to-the-fragment-identifier>scroll to the fragment</dfn> given a
  <code id=scrolling-to-a-fragment:document><a href=dom.html#document>Document</a></code> <var>document</var>:</p>

  <ol><li><p>If <var>document</var>'s <a href=#the-indicated-part-of-the-document id=scrolling-to-a-fragment:the-indicated-part-of-the-document>indicated part</a> is null, then set
   <var>document</var>'s <a href=#target-element id=scrolling-to-a-fragment:target-element>target element</a> to null.<li>
    <p>Otherwise, if <var>document</var>'s <a href=#the-indicated-part-of-the-document id=scrolling-to-a-fragment:the-indicated-part-of-the-document-2>indicated part</a> is <a href=#top-of-the-document id=scrolling-to-a-fragment:top-of-the-document>top of the
    document</a>, then:</p>

    <ol><li><p>Set <var>document</var>'s <a href=#target-element id=scrolling-to-a-fragment:target-element-2>target element</a> to null.<li><p><a id=scrolling-to-a-fragment:scroll-to-the-beginning-of-the-document href=https://drafts.csswg.org/cssom-view/#scroll-to-the-beginning-of-the-document data-x-internal=scroll-to-the-beginning-of-the-document>Scroll to the beginning of the document</a> for <var>document</var>.
     <a href=references.html#refsCSSOMVIEW>[CSSOMVIEW]</a><li><p>Return.</ol>
   <li>
    <p>Otherwise:</p>

    <ol><li><p><a id=scrolling-to-a-fragment:assert href=https://infra.spec.whatwg.org/#assert data-x-internal=assert>Assert</a>: <var>document</var>'s <a href=#the-indicated-part-of-the-document id=scrolling-to-a-fragment:the-indicated-part-of-the-document-3>indicated part</a> is an
     element.<li><p>Let <var>target</var> be <var>document</var>'s <a href=#the-indicated-part-of-the-document id=scrolling-to-a-fragment:the-indicated-part-of-the-document-4>indicated part</a>.<li><p>Set <var>document</var>'s <a href=#target-element id=scrolling-to-a-fragment:target-element-3>target element</a> to <var>target</var>.<li><p>Run the <a id=scrolling-to-a-fragment:ancestor-revealing-algorithm href=interaction.html#ancestor-revealing-algorithm>ancestor revealing algorithm</a> on <var>target</var>.<li><p><a href=https://drafts.csswg.org/cssom-view/#scroll-a-target-into-view id=scrolling-to-a-fragment:scroll-a-target-into-view data-x-internal=scroll-a-target-into-view>Scroll <var>target</var> into view</a>,
     with <i>behavior</i> set to "auto", <i>block</i> set to "start", and <i>inline</i>
     set to "nearest". <a href=references.html#refsCSSOMVIEW>[CSSOMVIEW]</a><li><p>Run the <a id=scrolling-to-a-fragment:focusing-steps href=interaction.html#focusing-steps>focusing steps</a> for <var>target</var>, with the
     <code id=scrolling-to-a-fragment:document-2><a href=dom.html#document>Document</a></code>'s <a id=scrolling-to-a-fragment:viewport href=https://drafts.csswg.org/css2/#viewport data-x-internal=viewport>viewport</a> as the <var>fallback target</var>.<li><p>Move the <a id=scrolling-to-a-fragment:sequential-focus-navigation-starting-point href=interaction.html#sequential-focus-navigation-starting-point>sequential focus navigation starting point</a> to
     <var>target</var>.</ol>
   </ol>

  <p>A <code id=scrolling-to-a-fragment:document-3><a href=dom.html#document>Document</a></code>'s <dfn id=the-indicated-part-of-the-document>indicated part</dfn> is
  the one that its <a href=https://dom.spec.whatwg.org/#concept-document-url id="scrolling-to-a-fragment:the-document's-address" data-x-internal="the-document's-address">URL</a>'s <a href=https://url.spec.whatwg.org/#concept-url-fragment id=scrolling-to-a-fragment:concept-url-fragment data-x-internal=concept-url-fragment>fragment</a> identifies, or null if the fragment does not
  identify anything. The semantics of the <a href=https://url.spec.whatwg.org/#concept-url-fragment id=scrolling-to-a-fragment:concept-url-fragment-2 data-x-internal=concept-url-fragment>fragment</a> in
  terms of mapping it to a node is defined by the specification that defines the <a id=scrolling-to-a-fragment:mime-type href=https://mimesniff.spec.whatwg.org/#mime-type data-x-internal=mime-type>MIME
  type</a> used by the <code id=scrolling-to-a-fragment:document-4><a href=dom.html#document>Document</a></code> (for example, the processing of <a href=https://url.spec.whatwg.org/#concept-url-fragment id=scrolling-to-a-fragment:concept-url-fragment-3 data-x-internal=concept-url-fragment>fragments</a> for <a href=https://mimesniff.spec.whatwg.org/#xml-mime-type id=scrolling-to-a-fragment:xml-mime-type data-x-internal=xml-mime-type>XML MIME
  types</a> is the responsibility of RFC7303). <a href=references.html#refsRFC7303>[RFC7303]</a></p>

  <p>There is also a <dfn id=target-element>target element</dfn> for each <code id=scrolling-to-a-fragment:document-5><a href=dom.html#document>Document</a></code>, which is used in
  defining the <code id=scrolling-to-a-fragment:selector-target><a href=semantics-other.html#selector-target>:target</a></code> pseudo-class and is updated by the
  above algorithm. It is initially null.</p>

  <p>For an <a href=https://dom.spec.whatwg.org/#html-document id=scrolling-to-a-fragment:html-documents data-x-internal=html-documents>HTML document</a> <var>document</var>, its
  <a href=#the-indicated-part-of-the-document id=scrolling-to-a-fragment:the-indicated-part-of-the-document-5>indicated part</a> is the result
  of <a href=#select-the-indicated-part id=scrolling-to-a-fragment:select-the-indicated-part>selecting the indicated part</a> given
  <var>document</var> and <var>document</var>'s <a href=https://dom.spec.whatwg.org/#concept-document-url id="scrolling-to-a-fragment:the-document's-address-2" data-x-internal="the-document's-address">URL</a>.</p>

  <p>To <dfn id=select-the-indicated-part>select the indicated part</dfn> given a <code id=scrolling-to-a-fragment:document-6><a href=dom.html#document>Document</a></code> <var>document</var> and a
  <a id=scrolling-to-a-fragment:url href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> <var>url</var>:</p>

  <ol><li><p>If <var>document</var>'s <a href=https://dom.spec.whatwg.org/#concept-document-url id="scrolling-to-a-fragment:the-document's-address-3" data-x-internal="the-document's-address">URL</a> does not <a href=https://url.spec.whatwg.org/#concept-url-equals id=scrolling-to-a-fragment:concept-url-equals data-x-internal=concept-url-equals>equal</a>
   <var>url</var> with <i id=scrolling-to-a-fragment:url-equals-exclude-fragments><a data-x-internal=url-equals-exclude-fragments href=https://url.spec.whatwg.org/#url-equals-exclude-fragments>exclude fragments</a></i> set to
   true, then return null.<li><p>Let <var>fragment</var> be <var>url</var>'s <a href=https://url.spec.whatwg.org/#concept-url-fragment id=scrolling-to-a-fragment:concept-url-fragment-4 data-x-internal=concept-url-fragment>fragment</a>.<li><p>If <var>fragment</var> is the empty string, then return the special value <dfn id=top-of-the-document>top of the
   document</dfn>.<li><p>Let <var>potentialIndicatedElement</var> be the result of <a href=#find-a-potential-indicated-element id=scrolling-to-a-fragment:find-a-potential-indicated-element>finding a potential indicated element</a> given <var>document</var> and
   <var>fragment</var>.<li><p>If <var>potentialIndicatedElement</var> is not null, then return
   <var>potentialIndicatedElement</var>.<li><p>Let <var>fragmentBytes</var> be the result of <a href=https://url.spec.whatwg.org/#string-percent-decode id=scrolling-to-a-fragment:percent-decode data-x-internal=percent-decode>percent-decoding</a> <var>fragment</var>.<li><p>Let <var>decodedFragment</var> be the result of running <a id=scrolling-to-a-fragment:utf-8-decode-without-bom href=https://encoding.spec.whatwg.org/#utf-8-decode-without-bom data-x-internal=utf-8-decode-without-bom>UTF-8 decode without
   BOM</a> on <var>fragmentBytes</var>.<li><p>Set <var>potentialIndicatedElement</var> to the result of <a href=#find-a-potential-indicated-element id=scrolling-to-a-fragment:find-a-potential-indicated-element-2>finding a potential indicated element</a> given <var>document</var> and
   <var>decodedFragment</var>.<li><p>If <var>potentialIndicatedElement</var> is not null, then return
   <var>potentialIndicatedElement</var>.<li><p>If <var>decodedFragment</var> is an <a id=scrolling-to-a-fragment:ascii-case-insensitive href=https://infra.spec.whatwg.org/#ascii-case-insensitive data-x-internal=ascii-case-insensitive>ASCII case-insensitive</a> match for the
   string <code>top</code>, then return the <a href=#top-of-the-document id=scrolling-to-a-fragment:top-of-the-document-2>top of the document</a>.<li><p>Return null.</ol>

  <p>To <dfn id=find-a-potential-indicated-element>find a potential indicated element</dfn> given a <code id=scrolling-to-a-fragment:document-7><a href=dom.html#document>Document</a></code>
  <var>document</var> and a string <var>fragment</var>, run these steps:</p>

  <ol><li><p>If there is an element <a href=https://dom.spec.whatwg.org/#in-a-document-tree id=scrolling-to-a-fragment:in-a-document-tree data-x-internal=in-a-document-tree>in the document tree</a>
   whose <a id=scrolling-to-a-fragment:root href=https://dom.spec.whatwg.org/#concept-tree-root data-x-internal=root>root</a> is <var>document</var> and that has an <a href=https://dom.spec.whatwg.org/#concept-id id=scrolling-to-a-fragment:concept-id data-x-internal=concept-id>ID</a> equal to <var>fragment</var>, then return the first such element
   in <a id=scrolling-to-a-fragment:tree-order href=https://dom.spec.whatwg.org/#concept-tree-order data-x-internal=tree-order>tree order</a>.<li><p>If there is an <code id=scrolling-to-a-fragment:the-a-element><a href=text-level-semantics.html#the-a-element>a</a></code> element <a href=https://dom.spec.whatwg.org/#in-a-document-tree id=scrolling-to-a-fragment:in-a-document-tree-2 data-x-internal=in-a-document-tree>in the document
   tree</a> whose <a id=scrolling-to-a-fragment:root-2 href=https://dom.spec.whatwg.org/#concept-tree-root data-x-internal=root>root</a> is <var>document</var> that has a <code id=scrolling-to-a-fragment:attr-a-name><a href=obsolete.html#attr-a-name>name</a></code> attribute whose value is equal to <var>fragment</var>, then
   return the first such element in <a id=scrolling-to-a-fragment:tree-order-2 href=https://dom.spec.whatwg.org/#concept-tree-order data-x-internal=tree-order>tree order</a>.<li><p>Return null.</ol>


  <h5 id=persisted-user-state-restoration><span class=secno>7.4.6.5</span> Persisted history entry state<a href=#persisted-user-state-restoration class=self-link></a></h5>

  <p>To <dfn id=save-persisted-state>save persisted state</dfn> to a <a href=#session-history-entry id=persisted-user-state-restoration:session-history-entry>session history entry</a>
  <var>entry</var>:</p>

  <ol><li><p>Set the <a href=#she-scroll-position id=persisted-user-state-restoration:she-scroll-position>scroll position data</a> of <var>entry</var>
   to contain the scroll positions for all of <var>entry</var>'s <a href=#she-document id=persisted-user-state-restoration:she-document>document</a>'s <a href=#restorable-scrollable-regions id=persisted-user-state-restoration:restorable-scrollable-regions>restorable scrollable regions</a>.<li><p>Optionally, update <var>entry</var>'s <a href=#she-other id=persisted-user-state-restoration:she-other>persisted user state</a>
   to reflect any state that the user agent wishes to persist, such as the values of form
   fields.</ol>

  <p id=restore-persisted-user-state>To <dfn id=restore-persisted-state>restore persisted state</dfn> from a <a href=#session-history-entry id=persisted-user-state-restoration:session-history-entry-2>session
  history entry</a> <var>entry</var>:</p>

  <ol><li>
    <p>If <var>entry</var>'s <a href=#she-scroll-restoration-mode id=persisted-user-state-restoration:she-scroll-restoration-mode>scroll restoration
    mode</a> is "<code id=persisted-user-state-restoration:dom-scrollrestoration-auto><a href=#dom-scrollrestoration-auto>auto</a></code>", and <var>entry</var>'s
    <a href=#she-document id=persisted-user-state-restoration:she-document-2>document</a>'s <a id=persisted-user-state-restoration:concept-relevant-global href=webappapis.html#concept-relevant-global>relevant global object</a>'s <a href=nav-history-apis.html#window-navigation-api id=persisted-user-state-restoration:window-navigation-api>navigation API</a>'s <a id=persisted-user-state-restoration:suppress-normal-scroll-restoration-during-ongoing-navigation href=nav-history-apis.html#suppress-normal-scroll-restoration-during-ongoing-navigation>suppress normal scroll restoration
    during ongoing navigation</a> is false, then <a href=#restore-scroll-position-data id=persisted-user-state-restoration:restore-scroll-position-data>restore scroll position data</a> given
    <var>entry</var>.</p>

    <p class=note>The user agent not restoring scroll positions does not imply that scroll
    positions will be left at any particular value (e.g., (0,0)). The actual scroll position depends
    on the navigation type and the user agent's particular caching strategy. So web applications
    cannot assume any particular scroll position but rather are urged to set it to what they want it
    to be.</p>

    <p class=note>If <a id=persisted-user-state-restoration:suppress-normal-scroll-restoration-during-ongoing-navigation-2 href=nav-history-apis.html#suppress-normal-scroll-restoration-during-ongoing-navigation>suppress normal scroll restoration during ongoing navigation</a> is
    true, then <a href=#restore-scroll-position-data id=persisted-user-state-restoration:restore-scroll-position-data-2>restoring scroll position data</a>
    might still happen at a later point, as part of <a href=nav-history-apis.html#navigateevent-finish id=persisted-user-state-restoration:navigateevent-finish>finishing</a> the relevant <code id=persisted-user-state-restoration:navigateevent><a href=nav-history-apis.html#navigateevent>NavigateEvent</a></code>, or via a
    <code id=persisted-user-state-restoration:dom-navigateevent-scroll><a href=nav-history-apis.html#dom-navigateevent-scroll>navigateEvent.scroll()</a></code> method call.</p>
   <li>
    <p>Optionally, update other aspects of <var>entry</var>'s <a href=#she-document id=persisted-user-state-restoration:she-document-3>document</a> and its rendering, for instance values of form fields,
    that the user agent had previously recorded in <var>entry</var>'s <a href=#she-other id=persisted-user-state-restoration:she-other-2>persisted user state</a>.</p>

    <p class=note>This can even include updating the <code id=persisted-user-state-restoration:attr-dir><a href=dom.html#attr-dir>dir</a></code> attribute
    of <code id=persisted-user-state-restoration:the-textarea-element><a href=form-elements.html#the-textarea-element>textarea</a></code> elements or <code id=persisted-user-state-restoration:the-input-element><a href=input.html#the-input-element>input</a></code> elements whose <code id=persisted-user-state-restoration:attr-input-type><a href=input.html#attr-input-type>type</a></code> attribute is in the <a href="input.html#text-(type=text)-state-and-search-state-(type=search)" id="persisted-user-state-restoration:text-(type=text)-state-and-search-state-(type=search)">Text</a>, <a href="input.html#text-(type=text)-state-and-search-state-(type=search)" id="persisted-user-state-restoration:text-(type=text)-state-and-search-state-(type=search)-2">Search</a>,
    <a href="input.html#telephone-state-(type=tel)" id="persisted-user-state-restoration:telephone-state-(type=tel)">Telephone</a>, <a href="input.html#url-state-(type=url)" id="persisted-user-state-restoration:url-state-(type=url)">URL</a>, or <a href="input.html#email-state-(type=email)" id="persisted-user-state-restoration:email-state-(type=email)">Email</a>
    state, if the persisted state includes the directionality of user input in such controls.</p>

    <p class=note>Restoring the value of form controls as part of this process does not fire any
    <code id=persisted-user-state-restoration:event-input><a data-x-internal=event-input href=https://w3c.github.io/uievents/#event-type-input>input</a></code> or <code id=persisted-user-state-restoration:event-change><a href=indices.html#event-change>change</a></code> events, but
    can trigger the <code>formStateRestoreCallback</code> of <a href=custom-elements.html#form-associated-custom-element id=persisted-user-state-restoration:form-associated-custom-element>form-associated custom elements</a>.</p>
   </ol>

  <hr>

  <p>Each <code id=persisted-user-state-restoration:document><a href=dom.html#document>Document</a></code> has a boolean <dfn id=has-been-scrolled-by-the-user>has been scrolled by the user</dfn>, initially
  false. If the user scrolls the document, the user agent must set that document's <a href=#has-been-scrolled-by-the-user id=persisted-user-state-restoration:has-been-scrolled-by-the-user>has been
  scrolled by the user</a> to true.</p>

  <p>The <dfn id=restorable-scrollable-regions>restorable scrollable regions</dfn> of a <code id=persisted-user-state-restoration:document-2><a href=dom.html#document>Document</a></code> <var>document</var>
  are <var>document</var>'s <a id=persisted-user-state-restoration:viewport href=https://drafts.csswg.org/css2/#viewport data-x-internal=viewport>viewport</a>, and all of <var>document</var>'s scrollable
  regions excepting any <a href=document-sequences.html#navigable-container id=persisted-user-state-restoration:navigable-container>navigable containers</a>.</p>

  <p class=note><a id=persisted-user-state-restoration:child-navigable href=document-sequences.html#child-navigable>Child navigable</a> scroll restoration is handled as part of state
  restoration for the <a href=#session-history-entry id=persisted-user-state-restoration:session-history-entry-3>session history entry</a> for those <a href=document-sequences.html#navigable id=persisted-user-state-restoration:navigable>navigables</a>' <code id=persisted-user-state-restoration:document-3><a href=dom.html#document>Document</a></code>s.</p>

  <p>To <dfn id=restore-scroll-position-data>restore scroll position data</dfn> given a <a href=#session-history-entry id=persisted-user-state-restoration:session-history-entry-4>session history entry</a>
  <var>entry</var>:</p>

  <ol><li><p>Let <var>document</var> be <var>entry</var>'s <a href=#she-document id=persisted-user-state-restoration:she-document-4>document</a>.<li><p>If <var>document</var>'s <a href=#has-been-scrolled-by-the-user id=persisted-user-state-restoration:has-been-scrolled-by-the-user-2>has been scrolled by the user</a> is true, then the
   user agent should return.<li>
    <p>The user agent should attempt to use <var>entry</var>'s <a href=#she-scroll-position id=persisted-user-state-restoration:she-scroll-position-2>scroll position data</a> to restore the scroll positions of
    <var>entry</var>'s <a href=#she-document id=persisted-user-state-restoration:she-document-5>document</a>'s <a href=#restorable-scrollable-regions id=persisted-user-state-restoration:restorable-scrollable-regions-2>restorable scrollable
    regions</a>. The user agent may continue to attempt to do so periodically, until
    <var>document</var>'s <a href=#has-been-scrolled-by-the-user id=persisted-user-state-restoration:has-been-scrolled-by-the-user-3>has been scrolled by the user</a> becomes true.</p>

    <p class=note>This is formulated as an <em>attempt</em>, which is potentially repeated until
    success or until the user scrolls, due to the fact that relevant content indicated by the <a href=#she-scroll-position id=persisted-user-state-restoration:she-scroll-position-3>scroll position data</a> might take some time to load from the
    network.</p>

    <p class=note>Scroll restoration might be affected by scroll anchoring.
    <a href=references.html#refsCSSSCROLLANCHORING>[CSSSCROLLANCHORING]</a></p>
   </ol>


  <nav><a href=document-sequences.html>← 7.3 Infrastructure for sequences of documents</a> — <a href=index.html>Table of Contents</a> — <a href=document-lifecycle.html>7.5 Document lifecycle →</a></nav>
